/** * Constructor for the <code>PrimitiveArray</code> object. This is * given the array type for the contact that is to be converted. An * array of the specified type is used to hold the deserialized * elements and will be the same length as the number of elements. * * @param context this is the context object used for serialization * @param type this is the actual field type from the schema * @param entry the entry type to be stored within the array * @param parent this is the name to wrap the array element with */ public PrimitiveArray(Context context, Type type, Type entry, String parent) { this.factory = new ArrayFactory(context, type); this.root = new Primitive(context, entry); this.parent = parent; this.entry = entry; this.type = type; }
/** * This is used to create a default instance of the field type. It * is up to the subclass to determine how to best instantiate an * object of the field type that best suits. This is used when the * empty value is required or to create the default type instance. * * @return a type which is used to instantiate the collection */ @Override public Object getInstance() throws Exception { Class type = getComponentType(); if(type != null) { return Array.newInstance(type, 0); } return null; }
/** * This is used to extract the component type for the array class * this factory represents. This is used when an array is to be * instantiated. If the class provided to the factory is not an * array then this will throw an exception. * * @return this returns the component type for the array */ private Class getComponentType() throws Exception { Class expect = getType(); if(!expect.isArray()) { throw new InstantiationException("The %s not an array for %s", expect, type); } return expect.getComponentType(); } }
/** * This <code>read</code> method will read the XML element list from * the provided node and deserialize its children as entry types. * This will deserialize each entry type as a primitive value. In * order to do this the parent string provided forms the element. * * @param node this is the XML element that is to be deserialized * * @return this returns the item to attach to the object contact */ public Object read(InputNode node) throws Exception{ Instance type = factory.getInstance(node); Object list = type.getInstance(); if(!type.isReference()) { return read(node, list); } return list; }
/** * Creates the array type to use. This will use the provided * XML element to determine the array type and provide a means * for creating an array with the <code>Value</code> object. If * the array size cannot be determined an exception is thrown. * * @param node this is the input node for the array element * * @return the object array type used for the instantiation */ public Instance getInstance(InputNode node) throws Exception { Position line = node.getPosition(); Value value = getOverride(node); if(value == null) { throw new ElementException("Array length required for %s at %s", type, line); } Class type = value.getType(); return getInstance(value, type); }
/** * This is used to determine whether the specified value has been * overridden by the strategy. If the item has been overridden * then no more serialization is require for that value, this is * effectively telling the serialization process to stop writing. * * @param node the node that a potential override is written to * @param value this is the object instance to be serialized * * @return returns true if the strategy overrides the object */ private boolean isOverridden(OutputNode node, Object value) throws Exception{ return factory.setOverride(entry, value, node); } }
/** * This <code>read</code> method will read the XML element list from * the provided node and deserialize its children as entry types. * This will deserialize each entry type as a primitive value. In * order to do this the parent string provided forms the element. * * @param node this is the XML element that is to be deserialized * * @return this returns the item to attach to the object contact */ public Object read(InputNode node) throws Exception{ Instance type = factory.getInstance(node); Object list = type.getInstance(); if(!type.isReference()) { return read(node, list); } return list; }
/** * Creates the array type to use. This will use the provided * XML element to determine the array type and provide a means * for creating an array with the <code>Value</code> object. If * the array size cannot be determined an exception is thrown. * * @param node this is the input node for the array element * * @return the object array type used for the instantiation */ public Instance getInstance(InputNode node) throws Exception { Position line = node.getPosition(); Value value = getOverride(node); if(value == null) { throw new ElementException("Array length required for %s at %s", type, line); } Class type = value.getType(); return getInstance(value, type); }
/** * This is used to determine whether the specified value has been * overridden by the strategy. If the item has been overridden * then no more serialization is require for that value, this is * effectively telling the serialization process to stop writing. * * @param node the node that a potential override is written to * @param value this is the object instance to be serialized * * @return returns true if the strategy overrides the object */ private boolean isOverridden(OutputNode node, Object value) throws Exception{ return factory.setOverride(entry, value, node); } }
/** * This <code>read</code> method will read the XML element list from * the provided node and deserialize its children as entry types. * This will deserialize each entry type as a primitive value. In * order to do this the parent string provided forms the element. * * @param node this is the XML element that is to be deserialized * * @return this returns the item to attach to the object contact */ public Object read(InputNode node) throws Exception{ Instance type = factory.getInstance(node); Object list = type.getInstance(); if(!type.isReference()) { return read(node, list); } return list; }
/** * Creates the array type to use. This will use the provided * XML element to determine the array type and provide a means * for creating an array with the <code>Value</code> object. If * the array size cannot be determined an exception is thrown. * * @param node this is the input node for the array element * * @return the object array type used for the instantiation */ public Instance getInstance(InputNode node) throws Exception { Position line = node.getPosition(); Value value = getOverride(node); if(value == null) { throw new ElementException("Array length required for %s at %s", type, line); } Class type = value.getType(); return getInstance(value, type); }
/** * Constructor for the <code>CompositeArray</code> object. This is * given the array type for the contact that is to be converted. An * array of the specified type is used to hold the deserialized * elements and will be the same length as the number of elements. * * @param context this is the context object used for serialization * @param type this is the field type for the array being used * @param entry this is the entry type for the array elements * @param parent this is the name to wrap the array element with */ public CompositeArray(Context context, Type type, Type entry, String parent) { this.factory = new ArrayFactory(context, type); this.root = new Traverser(context); this.parent = parent; this.entry = entry; this.type = type; }
/** * This is used to create a default instance of the field type. It * is up to the subclass to determine how to best instantiate an * object of the field type that best suits. This is used when the * empty value is required or to create the default type instance. * * @return a type which is used to instantiate the collection */ @Override public Object getInstance() throws Exception { Class type = getComponentType(); if(type != null) { return Array.newInstance(type, 0); } return null; }
/** * This is used to determine whether the specified value has been * overridden by the strategy. If the item has been overridden * then no more serialization is require for that value, this is * effectively telling the serialization process to stop writing. * * @param node the node that a potential override is written to * @param value this is the object instance to be serialized * * @return returns true if the strategy overrides the object */ private boolean isOverridden(OutputNode node, Object value) throws Exception{ return factory.setOverride(entry, value, node); } }
/** * This is used to extract the component type for the array class * this factory represents. This is used when an array is to be * instantiated. If the class provided to the factory is not an * array then this will throw an exception. * * @return this returns the component type for the array */ private Class getComponentType() throws Exception { Class expect = getType(); if(!expect.isArray()) { throw new InstantiationException("The %s not an array for %s", expect, type); } return expect.getComponentType(); } }
/** * This <code>read</code> method will read the XML element list from * the provided node and deserialize its children as entry types. * This ensures each entry type is deserialized as a root type, that * is, its <code>Root</code> annotation must be present and the * name of the entry element must match that root element name. * * @param node this is the XML element that is to be deserialized * * @return this returns the item to attach to the object contact */ public Object read(InputNode node) throws Exception{ Instance type = factory.getInstance(node); Object list = type.getInstance(); if(!type.isReference()) { return read(node, list); } return list; }
/** * Constructor for the <code>CompositeArray</code> object. This is * given the array type for the contact that is to be converted. An * array of the specified type is used to hold the deserialized * elements and will be the same length as the number of elements. * * @param context this is the context object used for serialization * @param type this is the field type for the array being used * @param entry this is the entry type for the array elements * @param parent this is the name to wrap the array element with */ public CompositeArray(Context context, Type type, Type entry, String parent) { this.factory = new ArrayFactory(context, type); this.root = new Traverser(context); this.parent = parent; this.entry = entry; this.type = type; }
/** * This is used to create a default instance of the field type. It * is up to the subclass to determine how to best instantiate an * object of the field type that best suits. This is used when the * empty value is required or to create the default type instance. * * @return a type which is used to instantiate the collection */ @Override public Object getInstance() throws Exception { Class type = getComponentType(); if(type != null) { return Array.newInstance(type, 0); } return null; }
/** * This is used to extract the component type for the array class * this factory represents. This is used when an array is to be * instantiated. If the class provided to the factory is not an * array then this will throw an exception. * * @return this returns the component type for the array */ private Class getComponentType() throws Exception { Class expect = getType(); if(!expect.isArray()) { throw new InstantiationException("The %s not an array for %s", expect, type); } return expect.getComponentType(); } }
/** * This <code>read</code> method will read the XML element list from * the provided node and deserialize its children as entry types. * This ensures each entry type is deserialized as a root type, that * is, its <code>Root</code> annotation must be present and the * name of the entry element must match that root element name. * * @param node this is the XML element that is to be deserialized * * @return this returns the item to attach to the object contact */ public Object read(InputNode node) throws Exception{ Instance type = factory.getInstance(node); Object list = type.getInstance(); if(!type.isReference()) { return read(node, list); } return list; }