public Type getComponent(int number) throws DataTypeException { Type type = getDelegate().getComponent(number); return unmodifiableType(type); }
/** * 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())); } }
public Type getComponent(int number) throws DataTypeException { Type type = getDelegate().getComponent(number); return unmodifiableType(type); }
/** 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())); } }
private static void setFirstComponentPrimitiveValue(Varies v, String theValue) throws DataTypeException { Composite c = (Composite) v.getData(); Type firstComponent = c.getComponent(0); setFirstComponentPrimitiveValue(firstComponent, 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 static void setFirstComponentPrimitiveValue(Varies v, String theValue) throws DataTypeException { Composite c = (Composite) v.getData(); Type firstComponent = c.getComponent(0); setFirstComponentPrimitiveValue(firstComponent, 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 static boolean isEmpty(Visitable v) throws HL7Exception { if (v == null) return true; if (v instanceof TSComponentOne) { TSComponentOne tsc1 = (TSComponentOne) v; return tsc1.getValue() == null || tsc1.getValue().isEmpty(); } if (v instanceof Composite && v.getClass().getName().endsWith(".TS")) { Composite ts = (Composite)v; return isEmpty(ts.getComponent(0)); } return v.isEmpty(); }
/** * Attempts to extract a Primitive from the given type. If it's a composite, drills down through * first components until a primitive is reached. */ private static Primitive getPrimitive(Type type) { if (type instanceof Primitive) { return (Primitive) type; } if (type instanceof Composite) { try { return getPrimitive(((Composite) type).getComponent(0)); } catch (HL7Exception e) { throw new RuntimeException("Internal error: HL7Exception thrown on Composite.getComponent(0)."); } } return getPrimitive(((Varies) type).getData()); }
/** * Attempts to extract a Primitive from the given type. If it's a composite, drills down through * first components until a primitive is reached. */ private static Primitive getPrimitive(Type type) { if (type instanceof Primitive) { return (Primitive) type; } if (type instanceof Composite) { try { return getPrimitive(((Composite) type).getComponent(0)); } catch (HL7Exception e) { throw new RuntimeException("Internal error: HL7Exception thrown on Composite.getComponent(0)."); } } return getPrimitive(((Varies) type).getData()); }
Component childProfile = profile.getComponent(i); try { Type child = comp.getComponent(i - 1); exList.addAll(doTestComponent(child, childProfile, profileID, validateChildren)); } catch (DataTypeException de) {
Component childProfile = profile.getComponent(i); try { Type child = comp.getComponent(i - 1); exList.addAll(doTestComponent(child, childProfile, profileID, validateChildren)); } catch (DataTypeException de) {
protected List<HL7Exception> doTestComponent(Type type, Component profile, String profileID, boolean theValidateChildren) throws ProfileException, HL7Exception { List<HL7Exception> exList = new ArrayList<HL7Exception>(); exList.addAll(testType(type, profile, null, profileID)); // test children if (profile.getSubComponents() > 0 && !profile.getUsage().equals("X") && (!type.isEmpty())) { if (Composite.class.isAssignableFrom(type.getClass())) { Composite comp = (Composite) type; if (theValidateChildren) { for (int i = 1; i <= profile.getSubComponents(); i++) { SubComponent childProfile = profile.getSubComponent(i); try { Type child = comp.getComponent(i - 1); exList.addAll(testType(child, childProfile, null, profileID)); } catch (DataTypeException de) { exList.add(new ProfileNotHL7CompliantException( "More subcomponents in profile than allowed in message: " + de.getMessage())); } } } checkExtraComponents(comp, profile.getSubComponents(), exList); } else { exList.add(new ProfileNotFollowedException("A component has primitive type " + type.getClass().getName() + " but the profile defines subcomponents")); } } return exList; }
protected List<HL7Exception> doTestComponent(Type type, Component profile, String profileID, boolean theValidateChildren) throws ProfileException, HL7Exception { List<HL7Exception> exList = new ArrayList<HL7Exception>(); exList.addAll(testType(type, profile, null, profileID)); // test children if (profile.getSubComponents() > 0 && !profile.getUsage().equals("X") && (!type.isEmpty())) { if (Composite.class.isAssignableFrom(type.getClass())) { Composite comp = (Composite) type; if (theValidateChildren) { for (int i = 1; i <= profile.getSubComponents(); i++) { SubComponent childProfile = profile.getSubComponent(i); try { Type child = comp.getComponent(i - 1); exList.addAll(testType(child, childProfile, null, profileID)); } catch (DataTypeException de) { exList.add(new ProfileNotHL7CompliantException( "More subcomponents in profile than allowed in message: " + de.getMessage())); } } } checkExtraComponents(comp, profile.getSubComponents(), exList); } else { exList.add(new ProfileNotFollowedException("A component has primitive type " + type.getClass().getName() + " but the profile defines subcomponents")); } } return exList; }
UsageInfo scUsage = new UsageInfo(subComponent); try { Type sub = comp.getComponent(i - 1); exList.addAll(testType(sub, subComponent.getDatatype(), scUsage, null)); } catch (DataTypeException de) {
component2 = component; if ((i == 1) && profile.isNullable() && PipeParser.encode(comp.getComponent(0), this.enc).equals("\"\"")) exList.addAll(testComponent(comp.getComponent(i - 1), component2)); } catch (DataTypeException de) { profileNotHL7Compliant(exList, COMPONENT_TYPE_MISMATCH, type.getName(), i);
if (comp <= numStandardComponents(type) || type instanceof GenericComposite) { try { return ((Composite) type).getComponent(comp - 1); } catch (DataTypeException e) { throw new RuntimeException(
if (comp <= numStandardComponents(type) || type instanceof GenericComposite) { try { return ((Composite) type).getComponent(comp - 1); } catch (DataTypeException e) { throw new RuntimeException(