/** * Removes given attribute from this container. * * @param attribute given attribute */ public void remove(final Attribute<?> attribute) { for (final Attribute<?> child : attributes) { if (child.getLocalName().equals(attribute.getLocalName())) { attributes.remove(child); break; } } }
/** * Adds given attribute into this container. Checks duplicities in attribute's names. * * @param attribute given attribute * @throws QtiAttributeException if container already contains attribute with same name */ public void add(final Attribute<?> attribute) { for (final Attribute<?> child : attributes) { if (child.getLocalName().equals(attribute.getLocalName()) && child.getNamespaceUri().equals(attribute.getNamespaceUri())) { throw new QtiAttributeException("Duplicate attribute name: " + attribute.computeXPath()); } } attributes.add(attribute); }
/** * Returns true if this container contains specified attribute; false otherwise. * * @param name attribute's name * @return true if this container contains specified attribute; false otherwise */ public boolean contains(final String name) { for (final Attribute<?> attribute : attributes) { if (attribute.getLocalName().equals(name)) { return true; } } return false; }
static { final Map<String, Attribute> map = new HashMap<String, Attribute>(); for (Attribute element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAP = map; }
/** @return the element's attribute matching the given name and namespace URI */ public final Attribute getAttribute(String name, String nsURI) { for (Attribute attrib : attribs) { if (areEqual(name, attrib.getLocalName()) && areEqual(nsURI, attrib.getNamespaceURI())) { return attrib; } } return null; }
/** * Adds the given attribute to the list, possibly replacing an existing attribute matching the new * attribute's name and namespace URI. */ public void addAttribute(Attribute attr) { if (null != attr.getParent()) { throw new PublicException(BpmRuntimeError.SDT_ATTRIBUTE_MUST_BE_DETACHED.raise()); } if (attribs.isEmpty()) { this.attribs = newArrayList(); } for (int i = 0; i < attribs.size(); ++i) { Attribute attrib = attribs.get(i); if (areEqual(attrib.getLocalName(), attr.getLocalName()) && areEqual(attrib.getNamespaceURI(), attr.getNamespaceURI())) { attrib.setParent(null); attribs.set(i, attr); attr.setParent(this); return; } } attribs.add(attr); attr.setParent(this); }
static ModelNode parseSso(XMLExtendedStreamReader reader) throws XMLStreamException { final ModelNode sso = new ModelNode(); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { requireNoNamespaceAttribute(reader, i); final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case CACHE_CONTAINER: case CACHE_NAME: case DOMAIN: case REAUTHENTICATE: sso.get(attribute.getLocalName()).set(value); break; default: throw unexpectedAttribute(reader, i); } } requireNoContent(reader); return sso; }
void parsePropConf(XMLExtendedStreamReader reader, ModelNode conf) throws XMLStreamException { final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { requireNoNamespaceAttribute(reader, i); final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ADVERTISE_SOCKET: case PROXY_LIST: case PROXY_URL: case ADVERTISE: case ADVERTISE_SECURITY_KEY: case EXCLUDED_CONTEXTS: case AUTO_ENABLE_CONTEXTS: case STOP_CONTEXT_TIMEOUT: case SOCKET_TIMEOUT: case STICKY_SESSION: case STICKY_SESSION_REMOVE: case STICKY_SESSION_FORCE: case WORKER_TIMEOUT: case MAX_ATTEMPTS: case FLUSH_PACKETS: case FLUSH_WAIT: case PING: case SMAX: case TTL: case NODE_TIMEOUT: case BALANCER: case LOAD_BALANCING_GROUP: case CONNECTOR: case SESSION_DRAINING_STRATEGY: ModClusterConfigResourceDefinition.ATTRIBUTES_BY_NAME .get(attribute.getLocalName()) .parseAndSetParameter(value, conf, reader); break; default: throw unexpectedAttribute(reader, i); } } }
/** * Gets attribute with given local name and namespace URI or null (if attribute is not found). * Silent parameter is useful for support of unknown attributes. * * @param localName name of requested attribute * @param silent if exception should be thrown in case attribute is not found * @return attribute with given name * @throws QtiAttributeException if silent is false and if attribute is not found */ private Attribute<?> get( final String localName, final String namespaceUri, final boolean silent) { Assert.notNull(localName, "localName"); Assert.notNull(namespaceUri, "namespaceUri"); for (final Attribute<?> attribute : attributes) { if (attribute.getLocalName().equals(localName) && attribute.getNamespaceUri().equals(namespaceUri)) { return attribute; } } if (silent) { return null; } throw new QtiAttributeException( "Cannot find attribute with namespace '" + namespaceUri + "' and local name '" + localName + "' in Node with XPath " + owner.computeXPath()); }
static ModelNode parseJSPConfiguration(XMLExtendedStreamReader reader) throws XMLStreamException { final ModelNode jsp = new ModelNode(); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { requireNoNamespaceAttribute(reader, i); final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case DEVELOPMENT: case DISABLED: case KEEP_GENERATED: case TRIM_SPACES: case TAG_POOLING: case MAPPED_FILE: case CHECK_INTERVAL: case MODIFIFICATION_TEST_INTERVAL: case RECOMPILE_ON_FAIL: case SMAP: case DUMP_SMAP: case GENERATE_STRINGS_AS_CHAR_ARRAYS: case ERROR_ON_USE_BEAN_INVALID_CLASS_ATTRIBUTE: case SCRATCH_DIR: case SOURCE_VM: case TARGET_VM: case JAVA_ENCODING: case X_POWERED_BY: case DISPLAY_SOURCE_FRAGMENT: jsp.get(attribute.getLocalName()).set(value); break; default: throw unexpectedAttribute(reader, i); } } requireNoContent(reader); return jsp; }
/** {@inheritDoc} */ @Override public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException { final ModelNode address = new ModelNode(); address.add(SUBSYSTEM, WebExtension.SUBSYSTEM_NAME); address.protect(); final ModelNode subsystem = new ModelNode(); subsystem.get(OP).set(ADD); subsystem.get(OP_ADDR).set(address); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { requireNoNamespaceAttribute(reader, i); final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NATIVE: case DEFAULT_VIRTUAL_SERVER: case INSTANCE_ID: subsystem.get(attribute.getLocalName()).set(value); break; default: throw unexpectedAttribute(reader, i); } } list.add(subsystem); // elements while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { switch (Namespace.forUri(reader.getNamespaceURI())) { case WEB_1_0: case WEB_1_1: { final Element element = Element.forName(reader.getLocalName()); switch (element) { case CONTAINER_CONFIG: { final ModelNode config = parseContainerConfig(reader); subsystem.get(CONTAINER_CONFIG).set(config); break; } case CONNECTOR: { parseConnector(reader, address, list); break; } case VIRTUAL_SERVER: { parseHost(reader, address, list); break; } default: { throw unexpectedElement(reader); } } break; } default: { throw unexpectedElement(reader); } } } }
private void writeAttribute( final XMLExtendedStreamWriter writer, final Attribute attr, final ModelNode value) throws XMLStreamException { writer.writeAttribute(attr.getLocalName(), value.asString()); }