/** * Encodes a Varies type by extracting it's data field and encoding that. Returns true if the * data field (or one of its components) contains a value. */ private boolean encodeVaries(Varies datatypeObject, Element datatypeElement) throws DataTypeException { boolean hasData = false; if (datatypeObject.getData() != null) { hasData = encode(datatypeObject.getData(), datatypeElement); } return hasData; }
/** * Encodes a Varies type by extracting it's data field and encoding that. Returns true if the * data field (or one of its components) contains a value. */ private boolean encodeVaries(Varies datatypeObject, Element datatypeElement) throws DataTypeException { boolean hasData = false; if (datatypeObject.getData() != null) { hasData = encode(datatypeObject.getData(), datatypeElement); } return hasData; }
Type obx5 = values[0].getData(); if ("NM".equals(hl7Datatype)) { String value = ((NM) obx5).getValue();
/** * 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; } }
/** * 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 testSubComponent(Type type, ValidationExceptionHandler<R> handler, Location l) { if (type instanceof Primitive) { testPrimitive((Primitive) type, handler, l); } else if (type instanceof Varies) { testSubComponent(((Varies) type).getData(), handler, l); } }
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; }
private static void setFirstComponentPrimitiveValue(Varies v, String theValue) throws DataTypeException { Composite c = (Composite) v.getData(); Type firstComponent = c.getComponent(0); setFirstComponentPrimitiveValue(firstComponent, theValue); }
private static void setFirstComponentPrimitiveValue(Varies v, String theValue) throws DataTypeException { Composite c = (Composite) v.getData(); Type firstComponent = c.getComponent(0); setFirstComponentPrimitiveValue(firstComponent, theValue); }
private void testSubComponent(Type type, ValidationExceptionHandler<R> handler, Location l) { if (type instanceof Primitive) { testPrimitive((Primitive) type, handler, l); } else if (type instanceof Varies) { testSubComponent(((Varies) type).getData(), handler, l); } }
/** * 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()); }
/** * Returns the number of components in the given type, i.e. the number of standard components * (e.g. 6 for CE) plus any extra components that have been added at runtime. * * @param t composite type * @return the number of components in the given type */ public static int numComponents(Type t) { if (!(t instanceof Varies)) { return numStandardComponents(t) + t.getExtraComponents().numComponents(); } return numComponents(((Varies) t).getData()); }
/** * Returns the number of components in the given type, i.e. the number of standard components * (e.g. 6 for CE) plus any extra components that have been added at runtime. * * @param t composite type * @return the number of components in the given type */ public static int numComponents(Type t) { if (!(t instanceof Varies)) { return numStandardComponents(t) + t.getExtraComponents().numComponents(); } return numComponents(((Varies) t).getData()); }
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 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); } }
/** * Parses an XML element into a Varies by determining whether the element is primitive or * composite, calling setData() on the Varies with a new generic primitive or composite as * appropriate, and then calling parse again with the new Type object. */ private void parseVaries(Varies datatypeObject, Element datatypeElement) throws HL7Exception { // figure out what data type it holds // short nodeType = datatypeElement.getFirstChild().getNodeType(); if (!hasChildElement(datatypeElement)) { // it's a primitive datatypeObject.setData(new GenericPrimitive(datatypeObject.getMessage())); } else { // it's a composite ... almost know what type, except that we don't have the version // here datatypeObject.setData(new GenericComposite(datatypeObject.getMessage())); } parse(datatypeObject.getData(), datatypeElement); }