final Type[] types = ((Composite) field).getComponents(); for (int i = 0; i < types.length; i++) { final Type type = types[i];
public HapiField(final Type type) { this.value = PipeParser.encode(type, EncodingCharacters.defaultInstance()); final List<HL7Component> componentList = new ArrayList<>(); if (type instanceof Composite) { final Composite composite = (Composite) type; for (final Type component : composite.getComponents()) { componentList.add(new HapiField(component)); } } final ExtraComponents extra = type.getExtraComponents(); if (extra != null && extra.numComponents() > 0) { final String singleFieldValue; if (type instanceof Primitive) { singleFieldValue = ((Primitive) type).getValue(); } else { singleFieldValue = this.value; } componentList.add(new SingleValueField(singleFieldValue)); for (int i = 0; i < extra.numComponents(); i++) { componentList.add(new HapiField(extra.getComponent(i))); } } this.components = Collections.unmodifiableList(componentList); }
public Type[] getComponents() { Type[] types = getDelegate().getComponents(); Type[] unmodifiableTypes = new Type[types.length]; if (types.length > 0) { for (int i = 0; i < types.length; i++) { unmodifiableTypes[i] = unmodifiableType(types[i]); } } return unmodifiableTypes; }
public Type[] getComponents() { Type[] types = getDelegate().getComponents(); Type[] unmodifiableTypes = new Type[types.length]; if (types.length > 0) { for (int i = 0; i < types.length; i++) { unmodifiableTypes[i] = unmodifiableType(types[i]); } } return unmodifiableTypes; }
private static int numStandardComponents(Type t) { if (t instanceof Composite) { return ((Composite) t).getComponents().length; } if (t instanceof Varies) { return numStandardComponents(((Varies) t).getData()); } return 1; }
private static int numStandardComponents(Type t) { if (t instanceof Composite) { return ((Composite) t).getComponents().length; } if (t instanceof Varies) { return numStandardComponents(((Varies) t).getData()); } return 1; }
/** * Tests for extra components (i.e. any not defined in the profile) */ protected List<ValidationException> checkUndefinedComponents(Composite comp, int numInProfile) { List<ValidationException> exList = new ArrayList<>(); StringBuilder extra = new StringBuilder(); for (int i = numInProfile; i < comp.getComponents().length; i++) { try { String s = comp.getComponent(i).encode(); if (s.length() > 0) { extra.append(s).append(enc.getComponentSeparator()); } } catch (HL7Exception de) { exList.add(new ValidationException(de)); } } profileViolatedWhen(extra.toString().length() > 0, exList, COMPONENT_NOT_DEFINED_IN_PROFILE, extra.toString()); return exList; }
/** Tests for extra components (ie any not defined in the profile) */ protected void checkExtraComponents(Composite comp, int numInProfile, List<HL7Exception> exList) throws ProfileException { StringBuilder extra = new StringBuilder(); for (int i = numInProfile; i < comp.getComponents().length; i++) { try { String s = PipeParser.encode(comp.getComponent(i), enc); if (s.length() > 0) { extra.append(s).append(enc.getComponentSeparator()); } } catch (DataTypeException de) { throw new ProfileException("Problem testing against profile", de); } } if (extra.length() > 0) { exList.add(new XElementPresentException( "The following components are not defined in the profile: " + extra.toString())); } }
/** Tests for extra components (ie any not defined in the profile) */ protected void checkExtraComponents(Composite comp, int numInProfile, List<HL7Exception> exList) throws ProfileException { StringBuilder extra = new StringBuilder(); for (int i = numInProfile; i < comp.getComponents().length; i++) { try { String s = PipeParser.encode(comp.getComponent(i), enc); if (s.length() > 0) { extra.append(s).append(enc.getComponentSeparator()); } } catch (DataTypeException de) { throw new ProfileException("Problem testing against profile", de); } } if (extra.length() > 0) { exList.add(new XElementPresentException( "The following components are not defined in the profile: " + extra.toString())); } }
/** * Encodes a Composite in XML by looping through it's components, creating new children for each * of them (with the appropriate names) and populating them by calling encode(Type, Element) * using these children. Returns true if at least one component contains a value. */ private boolean encodeComposite(Composite datatypeObject, Element datatypeElement) throws DataTypeException { Type[] components = datatypeObject.getComponents(); boolean hasValue = false; for (int i = 0; i < components.length; i++) { String name = makeElementName(datatypeObject, i + 1); Element newNode = datatypeElement.getOwnerDocument().createElement(name); boolean componentHasValue = encode(components[i], newNode); if (componentHasValue) { try { datatypeElement.appendChild(newNode); } catch (DOMException e) { throw new DataTypeException("DOMException encoding Composite: ", e); } hasValue = true; } } return hasValue; }
/** * Encodes a Composite in XML by looping through it's components, creating new children for each * of them (with the appropriate names) and populating them by calling encode(Type, Element) * using these children. Returns true if at least one component contains a value. */ private boolean encodeComposite(Composite datatypeObject, Element datatypeElement) throws DataTypeException { Type[] components = datatypeObject.getComponents(); boolean hasValue = false; for (int i = 0; i < components.length; i++) { String name = makeElementName(datatypeObject, i + 1); Element newNode = datatypeElement.getOwnerDocument().createElement(name); boolean componentHasValue = encode(components[i], newNode); if (componentHasValue) { try { datatypeElement.appendChild(newNode); } catch (DOMException e) { throw new DataTypeException("DOMException encoding Composite: ", e); } hasValue = true; } } return hasValue; }
Type[] children = datatypeObject.getComponents(); for (int i = 0; i < children.length; i++) { NodeList matchingElements = datatypeElement.getElementsByTagNameNS(NS, makeElementName(
/** * Returns an array containing the subcomponents within the first component of this Varies * object only if there are more than one of them. Otherwise, returns null. */ private static Type[] getFirstComponentSubcomponentsOnlyIfMoreThanOne(Varies v) throws DataTypeException { if (v.getData() instanceof Composite) { Composite c = (Composite) v.getData(); Type firstComponent = c.getComponent(0); if (firstComponent instanceof Varies) { Varies firstComponentVaries = (Varies) firstComponent; if (firstComponentVaries.getData() instanceof Composite) { return ((Composite)firstComponentVaries.getData()).getComponents(); } } } return null; } }
private void testComponent(Type type, ValidationExceptionHandler<R> handler, Location l) { if (type instanceof Composite) { Type[] component = ((Composite) type).getComponents(); for (int sub = 0; sub < component.length; sub++) { Location location = new Location(l).withSubcomponent(sub + 1); testSubComponent(component[sub], handler, location); } } else if (type instanceof Varies) { testComponent(((Varies) type).getData(), handler, l); } else { testPrimitive((Primitive) type, handler, l); } }
private void testComponent(Type type, ValidationExceptionHandler<R> handler, Location l) { if (type instanceof Composite) { Type[] component = ((Composite) type).getComponents(); for (int sub = 0; sub < component.length; sub++) { Location location = new Location(l).withSubcomponent(sub + 1); testSubComponent(component[sub], handler, location); } } else if (type instanceof Varies) { testComponent(((Varies) type).getData(), handler, l); } else { testPrimitive((Primitive) type, handler, l); } }
private static void setFirstComponentPrimitiveValue(Type theFirstComponent, String theValue) throws DataTypeException { if (theFirstComponent instanceof Varies) { Varies firstComponentVaries = (Varies)theFirstComponent; if (((Varies) theFirstComponent).getData() instanceof Composite) { Type[] subComponents = ((Composite)firstComponentVaries.getData()).getComponents(); setFirstComponentPrimitiveValue(subComponents[0], theValue); for (int i = 1; i < subComponents.length; i++) { setFirstComponentPrimitiveValue(subComponents[i], ""); } } else { Primitive p = (Primitive) firstComponentVaries.getData(); p.setValue(theValue); } } else if (theFirstComponent instanceof Composite) { Type[] subComponents = ((Composite)theFirstComponent).getComponents(); setFirstComponentPrimitiveValue(subComponents[0], theValue); for (int i = 1; i < subComponents.length; i++) { setFirstComponentPrimitiveValue(subComponents[i], ""); } } else { ((Primitive)theFirstComponent).setValue(theValue); } }
/** * Returns an array containing the subcomponents within the first component of this Varies * object only if there are more than one of them. Otherwise, returns null. */ private static Type[] getFirstComponentSubcomponentsOnlyIfMoreThanOne(Varies v) throws DataTypeException { if (v.getData() instanceof Composite) { Composite c = (Composite) v.getData(); Type firstComponent = c.getComponent(0); if (firstComponent instanceof Varies) { Varies firstComponentVaries = (Varies) firstComponent; if (firstComponentVaries.getData() instanceof Composite) { return ((Composite)firstComponentVaries.getData()).getComponents(); } } } return null; } }
private void testType(Type type, ValidationExceptionHandler<R> handler, Location l) { if (type instanceof Composite) { Type[] components = ((Composite) type).getComponents(); for (int comp = 0; comp < components.length; comp++) { Location location = new Location(l).withComponent(comp + 1); testComponent(components[comp], handler, location); } } else if (type instanceof Varies) { testType(((Varies) type).getData(), handler, l); } else { testPrimitive((Primitive) type, handler, l); } }
private void testType(Type type, ValidationExceptionHandler<R> handler, Location l) { if (type instanceof Composite) { Type[] components = ((Composite) type).getComponents(); for (int comp = 0; comp < components.length; comp++) { Location location = new Location(l).withComponent(comp + 1); testComponent(components[comp], handler, location); } } else if (type instanceof Varies) { testType(((Varies) type).getData(), handler, l); } else { testPrimitive((Primitive) type, handler, l); } }
private static void setFirstComponentPrimitiveValue(Type theFirstComponent, String theValue) throws DataTypeException { if (theFirstComponent instanceof Varies) { Varies firstComponentVaries = (Varies)theFirstComponent; if (((Varies) theFirstComponent).getData() instanceof Composite) { Type[] subComponents = ((Composite)firstComponentVaries.getData()).getComponents(); setFirstComponentPrimitiveValue(subComponents[0], theValue); for (int i = 1; i < subComponents.length; i++) { setFirstComponentPrimitiveValue(subComponents[i], ""); } } else { Primitive p = (Primitive) firstComponentVaries.getData(); p.setValue(theValue); } } else if (theFirstComponent instanceof Composite) { Type[] subComponents = ((Composite)theFirstComponent).getComponents(); setFirstComponentPrimitiveValue(subComponents[0], theValue); for (int i = 1; i < subComponents.length; i++) { setFirstComponentPrimitiveValue(subComponents[i], ""); } } else { ((Primitive)theFirstComponent).setValue(theValue); } }