/** * This is used to validate the configuration of the scanned class. * If an ordered element is specified but does not refer to an * existing element 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 validateElements(Class type, Order order) throws Exception { if(order != null) { for(String name : order.elements()) { if(!isElement(name)) { throw new ElementException("Ordered element '%s' missing for %s", name, type); } } } }
/** * This is used to validate the configuration of the scanned class. * If an ordered element is specified but does not refer to an * existing element 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 validateElements(Class type, Order order) throws Exception { if(order != null) { for(String name : order.elements()) { if(!isElement(name)) { throw new ElementException("Ordered element '%s' missing for %s", name, type); } } } }
/** * This is used to validate the configuration of the scanned class. * If an ordered element is specified but does not refer to an * existing element 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 validateElements(Class type, Order order) throws Exception { if(order != null) { for(String name : order.elements()) { if(!isElement(name)) { throw new ElementException("Ordered element '%s' missing for %s", name, type); } } } }
/** * 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 * @param list this is the array that is to be deserialized * * @return this returns the item to attach to the object contact */ public Object read(InputNode node, Object list) throws Exception{ int length = Array.getLength(list); for(int pos = 0; true; pos++) { Position line = node.getPosition(); InputNode next = node.getNext(); if(next == null) { return list; } if(pos >= length){ throw new ElementException("Array length missing or incorrect for %s at %s", type, line); } read(next, list, pos); } }
/** * This is used to acquire the dependent type for the annotated * list. This will simply return the type that the collection is * composed to hold. This must be a serializable type, that is, * a type that is annotated with the <code>Root</code> class. * * @return this returns the component type for the collection */ public Type getDependent() throws Exception { Contact contact = getContact(); if(item == void.class) { item = contact.getDependent(); } if(item == null) { throw new ElementException("Unable to determine generic type for %s", contact); } return new ClassType(item); }
/** * This is used to acquire the dependent type for the annotated * list. This will simply return the type that the collection is * composed to hold. This must be a serializable type, that is, * a type that is annotated with the <code>Root</code> class. * * @return this returns the component type for the collection */ public Type getDependent() throws Exception { Contact contact = getContact(); if(item == void.class) { item = contact.getDependent(); } if(item == null) { throw new ElementException("Unable to determine generic type for %s", contact); } return new ClassType(item); }
/** * This is used to acquire the dependent type for the annotated * list. This will simply return the type that the collection is * composed to hold. This must be a serializable type, that is, * a type that is annotated with the <code>Root</code> class. * * @return this returns the component type for the collection */ public Type getDependent() throws Exception { Contact contact = getContact(); if(item == void.class) { item = contact.getDependent(); } if(item == null) { throw new ElementException("Unable to determine generic type for %s", contact); } return new ClassType(item); }
/** * Validates the data read from the XML document by checking that when <code>MaxRetries</code> is supplied * <code>RetryInterval</code> contains positive non zero value. * * @throws Exception When the read XML is not valid */ @Validate public void validate() throws Exception { if (maxRetries > -1) if (fixedInterval <= 0) throw new ValueRequiredException( "ReceptionAwareness/RetryInterval must have positive non zero value if MaxRetries is set"); else if (!Utils.isNullOrEmpty(flexibleIntervalsText)) throw new ElementException("Invalid combination of MaxRetries and WaitIntervals settings"); // Create the array of intervals and check also that the specified intervals are valid calculateIntervals(); }
/** * 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); }
/** * 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 acquire the dependent type for the annotated * list. This will simply return the type that the map object is * composed to hold. This must be a serializable type, that is, * a type that is annotated with the <code>Root</code> class. * * @return this returns the component type for the map object */ public Type getDependent() throws Exception { Contact contact = getContact(); if(items == null) { items = contact.getDependents(); } if(items == null) { throw new ElementException("Unable to determine type for %s", contact); } if(items.length == 0) { return new ClassType(Object.class); } return new ClassType(items[0]); }
/** * 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 acquire the dependent type for the annotated * list. This will simply return the type that the map object is * composed to hold. This must be a serializable type, that is, * a type that is annotated with the <code>Root</code> class. * * @return this returns the component type for the map object */ public Type getDependent() throws Exception { Contact contact = getContact(); if(items == null) { items = contact.getDependents(); } if(items == null) { throw new ElementException("Unable to determine type for %s", contact); } if(items.length == 0) { return new ClassType(Object.class); } return new ClassType(items[0]); }
/** * 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 the node is valid. * * @param node this is the node to read the key value from * * @return this returns the value deserialized from the node */ public boolean validate(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 ElementException("Can not have %s as an attribute for %s at %s", expect, entry, line); } return validate(node, name); }
/** * This method is used to write the value to the specified node. * The value written to the node must be a composite object and if * the element map annotation is configured to have a key attribute * then this method will throw an exception. * * @param node this is the node that the value is written to * @param item this is the item that is to be written */ public void write(OutputNode node, Object item) throws Exception { Class expect = type.getType(); String key = entry.getKey(); if(entry.isAttribute()) { throw new ElementException("Can not have %s as an attribute for %s", expect, entry); } if(key == null) { key = context.getName(expect); } String name = style.getElement(key); root.write(node, item, expect, name); } }
/** * 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 registerElement(Label label) throws Exception { String name = label.getName(); if(elements.get(name) != null) { throw new ElementException("Duplicate annotation of name '%s' on %s", name, label); } if(!order.contains(name)) { order.add(name); } if(label.isTextList()) { list = label; } elements.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 registerElement(Label label) throws Exception { String name = label.getName(); if(elements.get(name) != null) { throw new ElementException("Duplicate annotation of name '%s' on %s", name, label); } if(!order.contains(name)) { order.add(name); } if(label.isTextList()) { list = label; } elements.put(name, label); }
/** * This method is used to write the value to the specified node. * The value written to the node must be a composite object and if * the element map annotation is configured to have a key attribute * then this method will throw an exception. * * @param node this is the node that the value is written to * @param item this is the item that is to be written */ public void write(OutputNode node, Object item) throws Exception { Class expect = type.getType(); String key = entry.getKey(); if(entry.isAttribute()) { throw new ElementException("Can not have %s as an attribute for %s", expect, entry); } if(key == null) { key = context.getName(expect); } String name = style.getElement(key); root.write(node, item, expect, name); } }
/** * This method is used to write the value to the specified node. * The value written to the node must be a composite object and if * the element map annotation is configured to have a key attribute * then this method will throw an exception. * * @param node this is the node that the value is written to * @param item this is the item that is to be written */ public void write(OutputNode node, Object item) throws Exception { Class expect = type.getType(); String key = entry.getKey(); if(entry.isAttribute()) { throw new ElementException("Can not have %s as an attribute for %s", expect, entry); } if(key == null) { key = context.getName(expect); } String name = style.getElement(key); root.write(node, item, expect, name); } }
/** * The <code>writeUnion</code> method is determine the unions * for a particular label and set the value of that union to * the same value as the label. This helps the serialization * process by ensuring once a union is written it is not * replaced. This is also required when writing inline lists. * * @param node this is the XML element to write elements to * @param source this is the source object to be serialized * @param section this is the section associated with the label * @param label this is the label used to define the XML element */ private void writeUnion(OutputNode node, Object source, Section section, Label label) throws Exception { Contact contact = label.getContact(); Object value = contact.get(source); Class expect = context.getType(type, source); if(value == null && label.isRequired()) { throw new ElementException("Value for %s is null in %s", label, expect); } Object replace = writeReplace(value); if(replace != null) { writeElement(node, replace, label); } criteria.set(label, replace); }