@Override public Object[] getEmptyArray() { return (Object[]) Array.newInstance(arrayType.getOuterComponentType().asClass(), 0); } }
@Override public Object[] getEmptyArray() { return (Object[]) Array.newInstance(arrayType.getOuterComponentType().asClass(), 0); } }
public DefaultArrayMarshaller(final MetaClass arrayType, final Marshaller<Object> outerMarshaller) { this.arrayType = Assert.notNull(arrayType); this.outerMarshaller = Assert.notNull("no outer marshaller specified for: " + arrayType.getOuterComponentType().getFullyQualifiedName(), outerMarshaller); Class<?> type = arrayType.asClass(); int dim = 0; while (type.isArray()) { dim++; type = type.getComponentType(); } this.dimensions = dim; }
public DefaultArrayMarshaller(final MetaClass arrayType, final Marshaller<Object> outerMarshaller) { this.arrayType = Assert.notNull(arrayType); this.outerMarshaller = Assert.notNull("no outer marshaller specified for: " + arrayType.getOuterComponentType().getFullyQualifiedName(), outerMarshaller); Class<?> type = arrayType.asClass(); int dim = 0; while (type.isArray()) { dim++; type = type.getComponentType(); } this.dimensions = dim; }
public Object demarshall(final EJValue a0, final MarshallingSession a1) { if (a0.isNull()) { return null; } else { final EJArray arr = a0.isArray(); final int[] dims = new int[dimensions]; dims[0] = arr.size(); final Object arrayInstance = Array.newInstance(arrayType.getOuterComponentType().asClass(), dims); _demarshall(dimensions - 1, arrayInstance, arr, a1); return arrayInstance; } }
public Object demarshall(final EJValue a0, final MarshallingSession a1) { if (a0.isNull()) { return null; } else { final EJArray arr = a0.isArray(); final int[] dims = new int[dimensions]; dims[0] = arr.size(); final Object arrayInstance = Array.newInstance(arrayType.getOuterComponentType().asClass(), dims); _demarshall(dimensions - 1, arrayInstance, arr, a1); return arrayInstance; } }
private boolean needsLazyInit(MetaClass type) { MetaClass compType = type.getOuterComponentType().getErased(); return (!compType.asUnboxed().isPrimitive() && !compType.equals(MetaClassFactory.get(String.class)) && !context .getDefinitionsFactory().hasBuiltInDefinition(compType)); }
private boolean needsLazyInit(MetaClass type) { MetaClass compType = type.getOuterComponentType().getErased(); return (!compType.asUnboxed().isPrimitive() && !compType.equals(MetaClassFactory.get(String.class)) && !context .getDefinitionsFactory().hasBuiltInDefinition(compType)); }
@Override public MetaClass getType() { final MetaClass ret; final int dims = GenUtil.getArrayDimensions(ref.getType()); if (ref.getType().isArray() && idx.length > 0) { final int newDims = dims - idx.length; if (newDims > 0) { ret = ref.getType().getOuterComponentType().asArrayOf(dims - idx.length); } else { ret = ref.getType().getOuterComponentType(); } } else { ret = ref.getType(); } return ret; } };
@Override public MetaClass getType() { final MetaClass ret; final int dims = GenUtil.getArrayDimensions(ref.getType()); if (ref.getType().isArray() && idx.length > 0) { final int newDims = dims - idx.length; if (newDims > 0) { ret = ref.getType().getOuterComponentType().asArrayOf(dims - idx.length); } else { ret = ref.getType().getOuterComponentType(); } } else { ret = ref.getType(); } return ret; } };
private Object _demarshall(final int dim, final Object arrayInstance, final EJArray a0, final MarshallingSession a1) { if (dim == 0) { for (int i = 0; i < a0.size(); i++) { Array.set(arrayInstance, i, outerMarshaller.demarshall(a0.get(i), a1)); } } else { for (int i = 0; i < a0.size(); i++) { Array.set(arrayInstance, i, _demarshall(dim - 1, Array.newInstance(arrayType.getOuterComponentType().asClass(), a0.get(i).isArray().size()), a0.get(i).isArray(), a1)); } } return arrayInstance; }
public static void assertAssignableTypes(final Context context, final MetaClass from, final MetaClass to) { if (!to.asBoxed().isAssignableFrom(from.asBoxed())) { if (to.isArray() && from.isArray() && GenUtil.getArrayDimensions(to) == GenUtil.getArrayDimensions(from) && to.getOuterComponentType().isAssignableFrom(from.getOuterComponentType())) { return; } if (!context.isPermissiveMode()) { if (classAliases.contains(from.getFullyQualifiedName()) && classAliases.contains(to.getFullyQualifiedName())) { // handle convertibility between MetaClass API and java Class reference. return; } throw new InvalidTypeException(to.getFullyQualifiedName() + " is not assignable from " + from.getFullyQualifiedName()); } } }
private Object _demarshall(final int dim, final Object arrayInstance, final EJArray a0, final MarshallingSession a1) { if (dim == 0) { for (int i = 0; i < a0.size(); i++) { Array.set(arrayInstance, i, outerMarshaller.demarshall(a0.get(i), a1)); } } else { for (int i = 0; i < a0.size(); i++) { Array.set(arrayInstance, i, _demarshall(dim - 1, Array.newInstance(arrayType.getOuterComponentType().asClass(), a0.get(i).isArray().size()), a0.get(i).isArray(), a1)); } } return arrayInstance; }
public static void assertAssignableTypes(final Context context, final MetaClass from, final MetaClass to) { if (!to.asBoxed().isAssignableFrom(from.asBoxed())) { if (to.isArray() && from.isArray() && GenUtil.getArrayDimensions(to) == GenUtil.getArrayDimensions(from) && to.getOuterComponentType().isAssignableFrom(from.getOuterComponentType())) { return; } if (!context.isPermissiveMode()) { if (classAliases.contains(from.getFullyQualifiedName()) && classAliases.contains(to.getFullyQualifiedName())) { // handle convertibility between MetaClass API and java Class reference. return; } throw new InvalidTypeException(to.getFullyQualifiedName() + " is not assignable from " + from.getFullyQualifiedName()); } } }
public static String getVarName(final MetaClass clazz) { return clazz.isArray() ? getArrayVarName(clazz.getOuterComponentType().getFullyQualifiedName()) + "_D" + GenUtil.getArrayDimensions(clazz) : getVarName(clazz.asBoxed().getFullyQualifiedName()); }
public static String getVarName(final MetaClass clazz) { return clazz.isArray() ? getArrayVarName(clazz.getOuterComponentType().getFullyQualifiedName()) + "_D" + GenUtil.getArrayDimensions(clazz) : getVarName(clazz.asBoxed().getFullyQualifiedName()); }
private int calcBufferSize(final List<MappingDefinition> stack, final MappingDefinition definition) { int bufSize = 128; if (!stack.contains(definition)) { stack.add(definition); for (final MemberMapping mapping : definition.getMemberMappings()) { MappingDefinition def = context.getDefinitionsFactory().getDefinition(mapping.getType()); if (def == null) { if (mapping.getType().isArray()) { def = context.getDefinitionsFactory().getDefinition(mapping.getType().getOuterComponentType().asBoxed()); // def could still be null in the case where the array component type is abstract or an // interface if (def != null) { bufSize += (calcBufferSize(stack, def)) * 4; } } continue; } bufSize += calcBufferSize(stack, def); } } return bufSize; }
@Override public void addDefinition(final MappingDefinition definition) { final String fqcn = definition.getMappingClass().getFullyQualifiedName(); final String internalName = definition.getMappingClass().getInternalName(); putDefinitionIfAbsent(fqcn, definition); if (definition.getMappingClass().isPrimitiveWrapper()) { putDefinitionIfAbsent(definition.getMappingClass().asUnboxed().getInternalName(), definition); putDefinitionIfAbsent(definition.getMappingClass().asUnboxed().getFullyQualifiedName(), definition); } if (!fqcn.equals(internalName) && definition.getMappingClass().isArray() && definition.getMappingClass().getOuterComponentType().isPrimitive()) { putDefinitionIfAbsent(internalName, definition); } if (log.isDebugEnabled()) log.debug("loaded definition: " + fqcn); }
@Override public void addDefinition(final MappingDefinition definition) { final String fqcn = definition.getMappingClass().getFullyQualifiedName(); final String internalName = definition.getMappingClass().getInternalName(); putDefinitionIfAbsent(fqcn, definition); if (definition.getMappingClass().isPrimitiveWrapper()) { putDefinitionIfAbsent(definition.getMappingClass().asUnboxed().getInternalName(), definition); putDefinitionIfAbsent(definition.getMappingClass().asUnboxed().getFullyQualifiedName(), definition); } if (!fqcn.equals(internalName) && definition.getMappingClass().isArray() && definition.getMappingClass().getOuterComponentType().isPrimitive()) { putDefinitionIfAbsent(internalName, definition); } if (log.isDebugEnabled()) log.debug("loaded definition: " + fqcn); }
private void generateMarshallers(final MarshallerGenerationCallback callback) { final Set<MetaClass> exposed = mappingContext.getDefinitionsFactory().getExposedClasses(); for (final MetaClass clazz : exposed) { mappingContext.registerGeneratedMarshaller(clazz.getFullyQualifiedName()); } final boolean lazyEnabled = CommonConfigAttribs.LAZY_LOAD_BUILTIN_MARSHALLERS.getBoolean(); for (final MetaClass cls : exposed) { final MetaClass compType = cls.getOuterComponentType(); final MappingDefinition definition = mappingContext.getDefinitionsFactory().getDefinition(compType); if (definition.getClientMarshallerClass() != null || definition.alreadyGenerated()) { continue; } if (target == MarshallerOutputTarget.Java && lazyEnabled && definition.isLazy()) { if (unlazyMarshallers.contains(compType.getFullyQualifiedName())) { definition.setLazy(false); } else { continue; } } addMarshaller(compType); callback.callback(compType); } }