/** * This is used to process the <code>Text</code> annotations that * are present in the scanned class. This will set the text label * for the class and an ensure that if there is more than one * text label within the class an exception is thrown. * * @param field the field the annotation was extracted from * @param type the annotation extracted from the field * * @throws Exception if there is more than one text annotation */ private void version(Contact field, Annotation type) throws Exception { Label label = support.getLabel(field, type); if(version != null) { throw new AttributeException("Multiple version annotations in %s", type); } version = label; }
/** * This is used to process the <code>Text</code> annotations that * are present in the scanned class. This will set the text label * for the class and an ensure that if there is more than one * text label within the class an exception is thrown. * * @param field the field the annotation was extracted from * @param type the annotation extracted from the field * * @throws Exception if there is more than one text annotation */ private void version(Contact field, Annotation type) throws Exception { Label label = support.getLabel(field, type); if(version != null) { throw new AttributeException("Multiple version annotations in %s", type); } version = label; }
/** * This is used to process the <code>Text</code> annotations that * are present in the scanned class. This will set the text label * for the class and an ensure that if there is more than one * text label within the class an exception is thrown. * * @param field the field the annotation was extracted from * @param type the annotation extracted from the field * * @throws Exception if there is more than one text annotation */ private void version(Contact field, Annotation type) throws Exception { Label label = support.getLabel(field, type); if(version != null) { throw new AttributeException("Multiple version annotations in %s", type); } version = label; }
/** * This is used to validate the configuration of the scanned class. * If an ordered attribute is specified but does not refer to an * existing attribute then this will throw an exception. * * @param type this is the object type that is being scanned * @param order this is the order that is to be validated */ private void validateAttributes(Class type, Order order) throws Exception { if(order != null) { for(String name : order.attributes()) { if(!isAttribute(name)) { throw new AttributeException("Ordered attribute '%s' missing in %s", name, type); } } } }
/** * This is used to validate the configuration of the scanned class. * If an ordered attribute is specified but does not refer to an * existing attribute then this will throw an exception. * * @param type this is the object type that is being scanned * @param order this is the order that is to be validated */ private void validateAttributes(Class type, Order order) throws Exception { if(order != null) { for(String name : order.attributes()) { if(!isAttribute(name)) { throw new AttributeException("Ordered attribute '%s' missing in %s", name, type); } } } }
/** * This is used to validate the configuration of the scanned class. * If an ordered attribute is specified but does not refer to an * existing attribute then this will throw an exception. * * @param type this is the object type that is being scanned * @param order this is the order that is to be validated */ private void validateAttributes(Class type, Order order) throws Exception { if(order != null) { for(String name : order.attributes()) { if(!isAttribute(name)) { throw new AttributeException("Ordered attribute '%s' missing in %s", name, type); } } } }
/** * This is used to register an XML entity within the model. The * registration process has the affect of telling the model that * it will contain a specific, named, XML entity. It also has * the affect of ordering them within the model, such that the * first registered entity is the first iterated over. * * @param label this is the label to register with the model */ public void registerAttribute(Label label) throws Exception { String name = label.getName(); if(attributes.get(name) != null) { throw new AttributeException("Duplicate annotation of name '%s' on %s", name, label); } attributes.put(name, label); }
/** * This is used to register an XML entity within the model. The * registration process has the affect of telling the model that * it will contain a specific, named, XML entity. It also has * the affect of ordering them within the model, such that the * first registered entity is the first iterated over. * * @param label this is the label to register with the model */ public void registerAttribute(Label label) throws Exception { String name = label.getName(); if(attributes.get(name) != null) { throw new AttributeException("Duplicate annotation of name '%s' on %s", name, label); } attributes.put(name, label); }
/** * This is used to register an XML entity within the model. The * registration process has the affect of telling the model that * it will contain a specific, named, XML entity. It also has * the affect of ordering them within the model, such that the * first registered entity is the first iterated over. * * @param label this is the label to register with the model */ public void registerAttribute(Label label) throws Exception { String name = label.getName(); if(attributes.get(name) != null) { throw new AttributeException("Duplicate annotation of name '%s' on %s", name, label); } attributes.put(name, label); }
/** * This is used to validate the individual attributes within the * model. Validation is done be acquiring all the attributes and * determining if they are null. If they are null this means that * an ordering has been imposed on a non-existing attribute. * * @param type this is the type this model is created for */ private void validateAttributes(Class type) throws Exception { Set<String> keys = attributes.keySet(); for(String name : keys) { Label label = attributes.get(name); if(label == null) { throw new AttributeException("Ordered attribute '%s' does not exist in %s", name, type); } if(expression != null) { expression.getAttribute(name); // prime cache } } }
/** * This is used to validate the individual attributes within the * model. Validation is done be acquiring all the attributes and * determining if they are null. If they are null this means that * an ordering has been imposed on a non-existing attribute. * * @param type this is the type this model is created for */ private void validateAttributes(Class type) throws Exception { Set<String> keys = attributes.keySet(); for(String name : keys) { Label label = attributes.get(name); if(label == null) { throw new AttributeException("Ordered attribute '%s' does not exist in %s", name, type); } if(expression != null) { expression.getAttribute(name); // prime cache } } }
/** * This is used to validate the individual attributes within the * model. Validation is done be acquiring all the attributes and * determining if they are null. If they are null this means that * an ordering has been imposed on a non-existing attribute. * * @param type this is the type this model is created for */ private void validateAttributes(Class type) throws Exception { Set<String> keys = attributes.keySet(); for(String name : keys) { Label label = attributes.get(name); if(label == null) { throw new AttributeException("Ordered attribute '%s' does not exist in %s", name, type); } if(expression != null) { expression.getAttribute(name); // prime cache } } }
/** * Creates a <code>Converter</code> that can convert an attribute * to a double value. This requires the context object used for * the current instance of XML serialization being performed. * * @param context this is context object used for serialization * * @return this returns the converted for this attribute object */ public Converter getConverter(Context context) throws Exception { String ignore = getEmpty(context); Type type = getContact(); if(!context.isFloat(type)) { throw new AttributeException("Cannot use %s to represent %s", label, type); } return new Primitive(context, type, ignore); }
/** * Creates a <code>Converter</code> that can convert an attribute * to a double value. This requires the context object used for * the current instance of XML serialization being performed. * * @param context this is context object used for serialization * * @return this returns the converted for this attribute object */ public Converter getConverter(Context context) throws Exception { String ignore = getEmpty(context); Type type = getContact(); if(!context.isFloat(type)) { throw new AttributeException("Cannot use %s to represent %s", label, type); } return new Primitive(context, type, ignore); }
/** * Creates a <code>Converter</code> that can convert an attribute * to a double value. This requires the context object used for * the current instance of XML serialization being performed. * * @param context this is context object used for serialization * * @return this returns the converted for this attribute object */ public Converter getConverter(Context context) throws Exception { String ignore = getEmpty(context); Type type = getContact(); if(!context.isFloat(type)) { throw new AttributeException("Cannot use %s to represent %s", label, type); } return new Primitive(context, type, ignore); }
/** * This method is used to read the key value from the node. The * value read from the node is resolved using the template filter. * If the key value can not be found according to the annotation * attributes then null is assumed and returned. * * @param node this is the node to read the key value from * * @return this returns the value deserialized from the node */ public Object read(InputNode node) throws Exception { Position line = node.getPosition(); Class expect = type.getType(); String name = entry.getKey(); if(name == null) { name = context.getName(expect); } if(entry.isAttribute()) { throw new AttributeException("Can not have %s as an attribute for %s at %s", expect, entry, line); } return read(node, name); }
/** * This method is used to read the key value from the node. The * value read from the node is resolved using the template filter. * If the key value can not be found according to the annotation * attributes then null is assumed and returned. * * @param node this is the node to read the key value from * * @return this returns the value deserialized from the node */ public Object read(InputNode node) throws Exception { Position line = node.getPosition(); Class expect = type.getType(); String name = entry.getKey(); if(name == null) { name = context.getName(expect); } if(entry.isAttribute()) { throw new AttributeException("Can not have %s as an attribute for %s at %s", expect, entry, line); } return read(node, name); }
/** * This method is used to read the key value from the node. The * value read from the node is resolved using the template filter. * If the key value can not be found according to the annotation * attributes then null is assumed and returned. * * @param node this is the node to read the key value from * * @return this returns the value deserialized from the node */ public Object read(InputNode node) throws Exception { Position line = node.getPosition(); Class expect = type.getType(); String name = entry.getKey(); if(name == null) { name = context.getName(expect); } if(entry.isAttribute()) { throw new AttributeException("Can not have %s as an attribute for %s at %s", expect, entry, line); } return read(node, name); }
/** * This write method is used to write all the attribute contacts from * the provided source object to the XML element. This visits all * the contacts marked with the <code>Attribute</code> annotation in * the source object. All annotated contacts are written as attributes * to the XML element. This will throw an exception if a required * contact within the source object is null. * * @param source this is the source object to be serialized * @param node this is the XML element to write attributes to * @param section this is the section that defines the XML structure */ private void writeAttributes(OutputNode node, Object source, Section section) throws Exception { LabelMap attributes = section.getAttributes(); for(Label label : attributes) { Contact contact = label.getContact(); Object value = contact.get(source); Class expect = context.getType(type, source); if(value == null) { value = label.getEmpty(context); } if(value == null && label.isRequired()) { throw new AttributeException("Value for %s is null in %s", label, expect); } writeAttribute(node, value, label); } }
/** * This write method is used to write all the attribute contacts from * the provided source object to the XML element. This visits all * the contacts marked with the <code>Attribute</code> annotation in * the source object. All annotated contacts are written as attributes * to the XML element. This will throw an exception if a required * contact within the source object is null. * * @param source this is the source object to be serialized * @param node this is the XML element to write attributes to * @param section this is the section that defines the XML structure */ private void writeAttributes(OutputNode node, Object source, Section section) throws Exception { LabelMap attributes = section.getAttributes(); for(Label label : attributes) { Contact contact = label.getContact(); Object value = contact.get(source); Class expect = context.getType(type, source); if(value == null) { value = label.getEmpty(context); } if(value == null && label.isRequired()) { throw new AttributeException("Value for %s is null in %s", label, expect); } writeAttribute(node, value, label); } }