public static void main(String[] args){ new Alphabet(); }
void addAlphabet(Alphabet a) { addElement(a.nameClass); }
context = ELEMENT_REPEAT_INTERLEAVE_CONTEXT; Alphabet a1; if (alpha != null && alpha.isEmpty()) a1 = alpha; else a1 = new Alphabet(); p1.checkRestrictions(context, dad, a1); if (a1.isEmpty()) p2.checkRestrictions(context, dad, a1); else { Alphabet a2 = new Alphabet(); p2.checkRestrictions(context, dad, a2); a1.checkOverlap(a2); if (alpha != null) { if (alpha != a1) alpha.addAlphabet(a1); alpha.addAlphabet(a2);
context = ELEMENT_REPEAT_INTERLEAVE_CONTEXT; Alphabet a1; if (alpha != null && alpha.isEmpty()) a1 = alpha; else a1 = new Alphabet(); p1.checkRestrictions(context, dad, a1); if (a1.isEmpty()) p2.checkRestrictions(context, dad, a1); else { Alphabet a2 = new Alphabet(); p2.checkRestrictions(context, dad, a2); a1.checkOverlap(a2); if (alpha != null) { if (alpha != a1) alpha.addAlphabet(a1); alpha.addAlphabet(a2);
Alphabet lowerSpace = new Alphabet("abcdefghijklmnopqrstuvwxyz ");
void addAlphabet(Alphabet a) { addElement(a.nameClass); }
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha) throws RestrictionViolationException { if (alpha != null) alpha.addElement(origNameClass); if (checkedRestrictions) return; switch (context) { case DATA_EXCEPT_CONTEXT: throw new RestrictionViolationException("data_except_contains_element"); case LIST_CONTEXT: throw new RestrictionViolationException("list_contains_element"); case ATTRIBUTE_CONTEXT: throw new RestrictionViolationException("attribute_contains_element"); } checkedRestrictions = true; try { p.checkRestrictions(ELEMENT_CONTEXT, new DuplicateAttributeDetector(), null); } catch (RestrictionViolationException e) { checkedRestrictions = false; e.maybeSetLocator(loc); throw e; } }
Validator validator = ...; Set<ConstraintViolation<Alphabet>> violations = validator.validate( new Alphabet(), AdminChecks.class );
@Override void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha) throws RestrictionViolationException { if (alpha != null) alpha.addElement(origNameClass); if (checkedRestrictions) return; switch (context) { case DATA_EXCEPT_CONTEXT: throw new RestrictionViolationException("data_except_contains_element"); case LIST_CONTEXT: throw new RestrictionViolationException("list_contains_element"); case ATTRIBUTE_CONTEXT: throw new RestrictionViolationException("attribute_contains_element"); } checkedRestrictions = true; try { p.checkRestrictions(ELEMENT_CONTEXT, new DuplicateAttributeDetector(), null); } catch (RestrictionViolationException e) { checkedRestrictions = false; e.maybeSetLocator(loc); throw e; } }
public class AlphabetToXML { public static void main(String[] args) { Alphabet alpha = new Alphabet("Apple", "Ball", "Cat", "Dog", "Elephant", "Fox"); try { String filePath = "PATH_TO_SAVE_YOUR_FILE"; File file = new File(filePath); JAXBContext jaxbContext = JAXBContext.newInstance(Alphabet.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(alpha, file); jaxbMarshaller.marshal(alpha, System.out); } catch (JAXBException e) { e.printStackTrace(); } } }