public int getFieldIdx(String fieldName) { Index i = fieldInfo.get(fieldName); if (i == null) { throw DynamicException.invalidPropertyName(null, fieldName); } return i.idx; }
/** * Exception throw when attempting to access a dynamic property by index * which does not have an associated mapping. Make sure the index used is * less then {@link DynamicType#getNumberOfProperties()}. * * @see DynamicTypeImpl#getMapping(String) */ public static DynamicException invalidPropertyIndex(DynamicType type, int propertyIndex) { DynamicException de = new DynamicException("Invalid DynamicEntity[" + type + "] property index: " + propertyIndex); de.setErrorCode(INVALID_PROPERTY_INDEX); return de; }
/** * Gets internal impl class of {@link DynamicType} * * @return Dynamic type of this entity * @throws DynamicException if type is null */ public DynamicTypeImpl getType() throws DynamicException { if (this.type == null) { throw DynamicException.entityHasNullType(this); } return this.type; }
propertyName); if (errorMsg != null) { throw DynamicException.invalidPropertyName(dpm.getType(), propertyName); dm = new UnknownMapping(propertyName); throw DynamicException.invalidGetPropertyType(dm, cce); throw DynamicException.invalidPropertyName(dpm.getType(), propertyName);
/** * Create using a loader and class name so that the parent class can be * lazily loaded when the writer is used to generate a dynamic class. * <p> * The loader must not be null and the parentClassName must not be null and * not an empty String. The parentClassName will be converted to a class * using the provided loader lazily. * * @see #getParentClass() * @see DynamicException#illegalDynamicClassWriter(DynamicClassLoader, * String) */ public DynamicClassWriter(String parentClassName) { if (parentClassName == null || parentClassName.length() == 0) { throw DynamicException.illegalParentClassName(parentClassName); } this.parentClassName = parentClassName; }
/** * Register a class to be dynamically created using the provided * {@link DynamicClassWriter}. The registered writer is used when the * {@link #findClass(String)} method is called back on this loader from the * {@link #loadClass(String)} call. * <p> * If a duplicate request is made for the same className and the writers are * not compatible a {@link DynamicException} will be thrown. If the * duplicate request contains a compatible writer then the second request is * ignored as the class may already have been generated. * * @see #findClass(String) */ public void addClass(String className, EclipseLinkClassWriter writer) throws DynamicException { EclipseLinkClassWriter existingWriter = getClassWriter(className); // Verify that the existing writer is compatible with the requested if (existingWriter != null) { if (!existingWriter.isCompatible(writer)) { throw DynamicException.incompatibleDuplicateWriters(className, existingWriter, writer); } } else { getClassWriters().put(className, writer == null ? getDefaultWriter() : writer); } }
(mapping.getAttributeClassification() != null && mapping.getAttributeClassification().isPrimitive())) { throw DynamicException.invalidSetPropertyType(mapping, value); throw DynamicException.invalidSetPropertyType(mapping, value);
@SuppressWarnings("unchecked") public <T> T get(String propertyName) { DatabaseMapping mapping = getType().getMapping(propertyName); Object value = mapping.getAttributeValueFromObject(this); if (mapping.isForeignReferenceMapping() && mapping.isLazy()) { // Force basic indirection to be instantiated if (value instanceof ValueHolderInterface) { value = ((ValueHolderInterface) value).getValue(); } // Force transparent indirection to be instantiated if (value instanceof IndirectContainer) { ((IndirectContainer) value).getValueHolder().getValue(); } } try { return (T) value; } catch (ClassCastException cce) { throw DynamicException.invalidGetPropertyType(mapping, cce); } }
propertyName); if (errorMsg != null) { throw DynamicException.invalidPropertyName(dpm.getType(), propertyName); dm = new UnknownMapping(propertyName); throw DynamicException.invalidGetPropertyType(dm, cce); throw DynamicException.invalidPropertyName(dpm.getType(), propertyName);
/** * Create using a loader and class name so that the parent class can be * lazily loaded when the writer is used to generate a dynamic class. * <p> * The loader must not be null and the parentClassName must not be null and * not an empty String. The parentClassName will be converted to a class * using the provided loader lazily. * * @see #getParentClass() * @see DynamicException#illegalDynamicClassWriter(DynamicClassLoader, * String) */ public DynamicClassWriter(String parentClassName) { if (parentClassName == null || parentClassName.length() == 0) { throw DynamicException.illegalParentClassName(parentClassName); } this.parentClassName = parentClassName; }
/** * Register a class to be dynamically created using the provided * {@link DynamicClassWriter}. The registered writer is used when the * {@link #findClass(String)} method is called back on this loader from the * {@link #loadClass(String)} call. * <p> * If a duplicate request is made for the same className and the writers are * not compatible a {@link DynamicException} will be thrown. If the * duplicate request contains a compatible writer then the second request is * ignored as the class may already have been generated. * * @see #findClass(String) */ public void addClass(String className, DynamicClassWriter writer) throws DynamicException { DynamicClassWriter existingWriter = getClassWriter(className); // Verify that the existing writer is compatible with the requested if (existingWriter != null) { if (!existingWriter.isCompatible(writer)) { throw DynamicException.incompatibleDuplicateWriters(className, existingWriter, writer); } } else { getClassWriters().put(className, writer == null ? getDefaultWriter() : writer); } }
(mapping.getAttributeClassification() != null && mapping.getAttributeClassification().isPrimitive())) { throw DynamicException.invalidSetPropertyType(mapping, null); throw DynamicException.invalidSetPropertyType(mapping, value);
/** * A {@link DynamicClassWriter} was attempted to be instantiated with a null * loader or invalid parentClassName. The parentClassName must not be null * or an empty string. */ public static DynamicException illegalDynamicClassWriter(DynamicClassLoader loader, String parentClassName) { DynamicException de = new DynamicException("Illegal DynamicClassWriter(" + loader + ", " + parentClassName + ")"); de.setErrorCode(ILLEGAL_DYNAMIC_CLASSWRITER); return de; }
public int getFieldIdx(String fieldName) { Index i = fieldInfo.get(fieldName); if (i == null) { throw DynamicException.invalidPropertyName(null, fieldName); } return i.idx; }
/** * Gets internal impl class of {@link DynamicType}. * * @return Dynamic type of this entity * @throws DynamicException if type is null */ public DynamicTypeImpl getType() throws DynamicException { DynamicType type = fetchPropertiesManager().getType(); if (type == null) { throw DynamicException.entityHasNullType(this); } return (DynamicTypeImpl) type; }
/** * Create using a loader and class name so that the parent class can be * lazily loaded when the writer is used to generate a dynamic class. * <p> * The loader must not be null and the parentClassName must not be null and * not an empty String. The parentClassName will be converted to a class * using the provided loader lazily. * * @see #getParentClass() * @see DynamicException#illegalDynamicClassWriter(DynamicClassLoader, * String) */ public DynamicClassWriter(String parentClassName) { if (parentClassName == null || parentClassName.length() == 0) { throw DynamicException.illegalParentClassName(parentClassName); } this.parentClassName = parentClassName; }
/** * Register a class to be dynamically created using the provided * {@link DynamicClassWriter}. The registered writer is used when the * {@link #findClass(String)} method is called back on this loader from the * {@link #loadClass(String)} call. * <p> * If a duplicate request is made for the same className and the writers are * not compatible a {@link DynamicException} will be thrown. If the * duplicate request contains a compatible writer then the second request is * ignored as the class may already have been generated. * * @see #findClass(String) */ public void addClass(String className, EclipseLinkClassWriter writer) throws DynamicException { EclipseLinkClassWriter existingWriter = getClassWriter(className); // Verify that the existing writer is compatible with the requested if (existingWriter != null) { if (!existingWriter.isCompatible(writer)) { throw DynamicException.incompatibleDuplicateWriters(className, existingWriter, writer); } } else { getClassWriters().put(className, writer == null ? getDefaultWriter() : writer); } }
(mapping.getAttributeClassification() != null && mapping.getAttributeClassification().isPrimitive())) { throw DynamicException.invalidSetPropertyType(mapping, value); throw DynamicException.invalidSetPropertyType(mapping, value);
/** * A request to get a persistent value from a DynamicEntity was made * providing a propertyName that does not correspond to any mappings in the * underlying descriptor. * * @see DynamicEntityImpl#get(String) * */ public static DynamicException invalidPropertyName(DynamicType type, String propertyName) { DynamicException de = new DynamicException("Invalid DynamicEntity[" + type + "] property name: " + propertyName); de.setErrorCode(INVALID_PROPERTY_NAME); return de; }
public void checkSet(String propertyName, Object value) { if (contains(propertyName)) { type.checkSet(propertyName, value); } else { throw DynamicException.invalidPropertyName(type, propertyName); } }