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); }
@Override public Variable getComponent(int comp) { if (comp >= numComponents()) { throw new IllegalArgumentException(String.format( "Extra Component with index %d is not available and cannot be added to unmodifiable type", comp)); } return unmodifiableType(delegate.getComponent(comp)); }
@Override public int numComponents() { return delegate.numComponents(); }
/** * {@inheritDoc } */ public boolean isEmpty() throws HL7Exception { return extra.isEmpty(); }
public UnmodifiableExtraComponents(ExtraComponents delegate) { super(delegate.getMessage()); this.delegate = delegate; }
/** * Returns the component at the given location, creating it * and all preceeding components if necessary. * * @param comp the extra component number starting at 0 (i.e. 0 is the first * extra component) * @return component at the given index */ public Variable getComponent(int comp) { ensureComponentAndPredecessorsExist(comp); return this.comps.get(comp); }
/** * Creates a new instance of AbstractType * @param message message to which this type belongs */ public AbstractType(Message message) { extra = new ExtraComponents(message); this.message = message; }
/** * {@inheritDoc } */ public void clear() { extra.clear(); }
@Override public String toString() { return delegate.toString(); }
@Override public Variable getComponent(int comp) { if (comp >= numComponents()) { throw new IllegalArgumentException(String.format( "Extra Component with index %d is not available and cannot be added to unmodifiable type", comp)); } return unmodifiableType(delegate.getComponent(comp)); }
@Override public int numComponents() { return delegate.numComponents(); }
@Override public boolean isEmpty() throws HL7Exception { return delegate.isEmpty(); }
public UnmodifiableExtraComponents(ExtraComponents delegate) { super(delegate.getMessage()); this.delegate = delegate; }
/** * Returns the component at the given location, creating it * and all preceeding components if necessary. * * @param comp the extra component number starting at 0 (i.e. 0 is the first * extra component) * @return component at the given index */ public Variable getComponent(int comp) { ensureComponentAndPredecessorsExist(comp); return this.comps.get(comp); }
/** * Creates a new instance of AbstractType * @param message message to which this type belongs */ public AbstractType(Message message) { extra = new ExtraComponents(message); this.message = message; }
/** * {@inheritDoc } */ public void clear() { extra.clear(); }
@Override public String toString() { return delegate.toString(); }
if (index != -1) { String nextSubComponent = string.substring(prevIndex, index); getExtraComponents().getComponent(getExtraComponents().numComponents()).parse(nextSubComponent); } else { String nextSubComponent = string.substring(prevIndex); if (nextSubComponent.length() > 0) { getExtraComponents().getComponent(getExtraComponents().numComponents()).parse(nextSubComponent);
NodeList matchingElements = datatypeElement.getElementsByTagNameNS(NS, makeElementName(datatypeObject, children.length + nextExtraCmpIndex + 1)); if (matchingElements.getLength() > 0) { parse(datatypeObject.getExtraComponents().getComponent(nextExtraCmpIndex), (Element) matchingElements.item(0)); foundExtraComponent = true;
/** * 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()); }