/** * 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 registerText(Label label) throws Exception { if(text != null) { throw new TextException("Duplicate text annotation on %s", label); } text = 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 registerText(Label label) throws Exception { if(text != null) { throw new TextException("Duplicate text annotation on %s", label); } text = 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 registerText(Label label) throws Exception { if(text != null) { throw new TextException("Duplicate text annotation on %s", label); } text = label; }
/** * This method is used to validate the model based on whether it * has a text annotation. If this model has a text annotation then * it is checked to see if it is a composite model or has any * elements. If it has either then the model is considered invalid. * * @param type this is the object type representing the schema */ private void validateText(Class type) throws Exception { if(text != null) { if(!elements.isEmpty()) { throw new TextException("Text annotation %s used with elements in %s", text, type); } if(isComposite()) { throw new TextException("Text annotation %s can not be used with paths in %s", text, type); } } }
/** * This method is used to validate the model based on whether it * has a text annotation. If this model has a text annotation then * it is checked to see if it is a composite model or has any * elements. If it has either then the model is considered invalid. * * @param type this is the object type representing the schema */ private void validateText(Class type) throws Exception { if(text != null) { if(!elements.isEmpty()) { throw new TextException("Text annotation %s used with elements in %s", text, type); } if(isComposite()) { throw new TextException("Text annotation %s can not be used with paths in %s", text, type); } } }
/** * This method is used to validate the model based on whether it * has a text annotation. If this model has a text annotation then * it is checked to see if it is a composite model or has any * elements. If it has either then the model is considered invalid. * * @param type this is the object type representing the schema */ private void validateText(Class type) throws Exception { if(text != null) { if(!elements.isEmpty()) { throw new TextException("Text annotation %s used with elements in %s", text, type); } if(isComposite()) { throw new TextException("Text annotation %s can not be used with paths in %s", text, type); } } }
/** * Is a helper to construct the array of {@link Interval} objects. */ private void calculateIntervals() throws TextException { if (!Utils.isNullOrEmpty(flexibleIntervalsText)) { if (flexibleIntervalsText.endsWith(",")) throw new TextException("WaitIntervals does not contain valid list of intervals!"); try { final String[] sIntervals = flexibleIntervalsText.split(","); this.waitIntervals = new Interval[sIntervals.length]; for(int i = 0; i < sIntervals.length; i++) { int intervalLength = Integer.parseInt(sIntervals[i].trim()); if (intervalLength < 0) throw new TextException("WaitIntervals must contain non-negative integers!"); this.waitIntervals[i] = new Interval(intervalLength, TimeUnit.SECONDS); } } catch (NumberFormatException nan) { throw new TextException("WaitIntervals does not contain valid list of intervals!"); } } else if (maxRetries >= 0) { // Configuration with fixed intervals, convert to new structure so add an extra wait interval waitIntervals = new Interval[maxRetries + 1]; for(int i = 0; i < maxRetries + 1; i++) waitIntervals[i] = new Interval(fixedInterval, TimeUnit.SECONDS); } }
throw new TextException("Elements used with %s in %s", label, type); throw new TextException("Illegal entry of %s with text annotations on %s in %s", actual, label, type); throw new TextException("Paths used with %s in %s", label, type);
throw new TextException("Elements used with %s in %s", label, type); throw new TextException("Illegal entry of %s with text annotations on %s in %s", actual, label, type); throw new TextException("Paths used with %s in %s", label, type);
throw new TextException("Elements used with %s in %s", label, type); throw new TextException("Illegal entry of %s with text annotations on %s in %s", actual, label, type); throw new TextException("Paths used with %s in %s", label, type);
/** * This method returns a <code>Converter</code> which can be used to * convert an XML node into an object value and vice versa. The * converter requires only the context object in order to perform * serialization or deserialization of the provided XML node. * * @param context this is the context object for the serialization * * @return this returns an object that is used for conversion */ public Converter getConverter(Context context) throws Exception { Type type = getContact(); if(!label.isCollection()) { throw new TextException("Cannot use %s to represent %s", type, label); } return new TextList(context, type, label); }
/** * This method returns a <code>Converter</code> which can be used to * convert an XML node into an object value and vice versa. The * converter requires only the context object in order to perform * serialization or deserialization of the provided XML node. * * @param context this is the context object for the serialization * * @return this returns an object that is used for conversion */ public Converter getConverter(Context context) throws Exception { Type type = getContact(); if(!label.isCollection()) { throw new TextException("Cannot use %s to represent %s", type, label); } return new TextList(context, type, label); }
/** * This method returns a <code>Converter</code> which can be used to * convert an XML node into an object value and vice versa. The * converter requires only the context object in order to perform * serialization or deserialization of the provided XML node. * * @param context this is the context object for the serialization * * @return this returns an object that is used for conversion */ public Converter getConverter(Context context) throws Exception { Type type = getContact(); if(!label.isCollection()) { throw new TextException("Cannot use %s to represent %s", type, label); } return new TextList(context, type, label); }
/** * This is used to validate the configuration of the scanned class. * If a <code>Text</code> annotation has been used with elements * then validation will fail and an exception will be thrown. * * @param type this is the object type that is being scanned */ private void validateText(Class type) throws Exception { Label label = root.getText(); if(label != null) { if(!label.isTextList()) { if(!elements.isEmpty()) { throw new TextException("Elements used with %s in %s", label, type); } if(root.isComposite()) { throw new TextException("Paths used with %s in %s", label, type); } } } else { if(scanner.isEmpty()) { primitive = isEmpty(); } } }
/** * This is used to validate the configuration of the scanned class. * If a <code>Text</code> annotation has been used with elements * then validation will fail and an exception will be thrown. * * @param type this is the object type that is being scanned */ private void validateText(Class type) throws Exception { Label label = root.getText(); if(label != null) { if(!label.isTextList()) { if(!elements.isEmpty()) { throw new TextException("Elements used with %s in %s", label, type); } if(root.isComposite()) { throw new TextException("Paths used with %s in %s", label, type); } } } else { if(scanner.isEmpty()) { primitive = isEmpty(); } } }
/** * This is used to validate the configuration of the scanned class. * If a <code>Text</code> annotation has been used with elements * then validation will fail and an exception will be thrown. * * @param type this is the object type that is being scanned */ private void validateText(Class type) throws Exception { Label label = root.getText(); if(label != null) { if(!label.isTextList()) { if(!elements.isEmpty()) { throw new TextException("Elements used with %s in %s", label, type); } if(root.isComposite()) { throw new TextException("Paths used with %s in %s", label, type); } } } else { if(scanner.isEmpty()) { primitive = isEmpty(); } } }
/** * Creates a converter that can be used to transform an XML node to * an object and vice versa. The converter created will handles * only XML text and requires the context object to be provided. * * @param context this is the context object used for serialization * * @return this returns a converter for serializing XML elements */ public Converter getConverter(Context context) throws Exception { String ignore = getEmpty(context); Type type = getContact(); if(!context.isPrimitive(type)) { throw new TextException("Cannot use %s to represent %s", type, label); } return new Primitive(context, type, ignore); }
/** * Creates a converter that can be used to transform an XML node to * an object and vice versa. The converter created will handles * only XML text and requires the context object to be provided. * * @param context this is the context object used for serialization * * @return this returns a converter for serializing XML elements */ public Converter getConverter(Context context) throws Exception { String ignore = getEmpty(context); Type type = getContact(); if(!context.isPrimitive(type)) { throw new TextException("Cannot use %s to represent %s", type, label); } return new Primitive(context, type, ignore); }
/** * Creates a converter that can be used to transform an XML node to * an object and vice versa. The converter created will handles * only XML text and requires the context object to be provided. * * @param context this is the context object used for serialization * * @return this returns a converter for serializing XML elements */ public Converter getConverter(Context context) throws Exception { String ignore = getEmpty(context); Type type = getContact(); if(!context.isPrimitive(type)) { throw new TextException("Cannot use %s to represent %s", type, label); } return new Primitive(context, type, ignore); }
/** * This write method is used to write the text contact from the * provided source object to the XML element. This takes the text * value from the source object and writes it to the single contact * marked with the <code>Text</code> annotation. If the value is * null and the contact value is required an exception is thrown. * * @param source this is the source object to be serialized * @param node this is the XML element to write text value to * @param section this is used to track the referenced elements */ private void writeText(OutputNode node, Object source, Section section) throws Exception { Label label = section.getText(); if(label != null) { 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 TextException("Value for %s is null in %s", label, expect); } writeText(node, value, label); } }