List of usage examples for javax.xml.namespace QName equals
public final boolean equals(Object objectToTest)
Test this QName
for equality with another Object
.
If the Object
to be tested is not a QName
or is null
, then this method returns false
.
Two QName
s are considered equal if and only if both the Namespace URI and local part are equal.
From source file:org.plasma.provisioning.xsd.ConverterSupport.java
public String findOpenAttributeValue(QName qname, OpenAttrs attrs, boolean supressError) { Iterator<QName> iter = attrs.getOtherAttributes().keySet().iterator(); while (iter.hasNext()) { QName key = iter.next(); if (key.equals(qname)) { String result = attrs.getOtherAttributes().get(key); return result; }/* ww w . ja v a 2 s.co m*/ } if (!supressError) throw new IllegalArgumentException("attribute '" + qname.toString() + "' not found"); return null; }
From source file:org.slc.sli.api.resources.config.StAXMsgBodyReader.java
/** * Reads individual elements inside of a XML Document * @param reader xml reader/*from w ww . j ava2 s. co m*/ * @return a pair representing the Object value of the element (Left) as well as * a boolean value representing either true (part of a list) or false * (single value) * @throws XMLStreamException on malformed XML */ private static final Pair<Object, Boolean> readElement(final XMLStreamReader reader) throws XMLStreamException { final QName elementName = reader.getName(); final StringBuilder sb = new StringBuilder(); final Map<String, Object> data = new HashMap<String, Object>(); final Boolean member = isMember(reader); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { final QName key = reader.getName(); final Pair<Object, Boolean> elem = readElement(reader); addToElements(key.getLocalPart(), elem, data); break; } case XMLStreamConstants.END_ELEMENT: { if (elementName.equals(reader.getName())) { if (data.size() > 0) { return new ImmutablePair<Object, Boolean>(data, member); } else { return new ImmutablePair<Object, Boolean>(sb.toString(), member); } } else { throw new XMLStreamException(reader.getName().getLocalPart()); } } case XMLStreamConstants.CHARACTERS: { sb.append(reader.getText()); break; } default: { throw new XMLStreamException(); } } } throw new XMLStreamException(); }
From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java
private static final DmElement readMixedElement(final XMLStreamReader reader) throws XMLStreamException { final QName name = reader.getName(); final List<DmNode> children = new LinkedList<DmNode>(); while (reader.hasNext()) { reader.next();//from w ww . j ava 2 s . c om switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { children.add(readMixedElement(reader)); break; } case XMLStreamConstants.END_ELEMENT: { if (name.equals(reader.getName())) { return new DmElement(name, children); } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { // Assume that the element will coalesce text nodes. children.add(new DmText(reader.getText())); break; } case XMLStreamConstants.COMMENT: { // Ignore for now. break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); }
From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java
protected static final boolean match(final QName name, final XMLStreamReader reader) { return name.equals(reader.getName()); }
From source file:org.unitedinternet.cosmo.dav.acl.resource.DavUserPrincipalTest.java
/** * Tests load properties./* w w w. j a v a2 s . c om*/ * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testLoadProperties() throws Exception { //initialize it on order to be able to run test testHelper.getSecurityManager().initiateSecurityContext("test", "test"); DavUserPrincipal p = testHelper.getPrincipal(testHelper.getUser()); // section 4 DisplayName displayName = (DisplayName) p.getProperty(DavPropertyName.DISPLAYNAME); Assert.assertNotNull("No displayname property", displayName); Assert.assertTrue("Empty displayname ", !StringUtils.isBlank(displayName.getDisplayName())); ResourceType resourceType = (ResourceType) p.getProperty(DavPropertyName.RESOURCETYPE); Assert.assertNotNull("No resourcetype property", resourceType); boolean foundPrincipalQname = false; for (QName qname : resourceType.getQnames()) { if (qname.equals(RESOURCE_TYPE_PRINCIPAL)) { foundPrincipalQname = true; break; } } Assert.assertTrue("Principal qname not found", foundPrincipalQname); // 4.1 AlternateUriSet alternateUriSet = (AlternateUriSet) p.getProperty(ALTERNATEURISET); Assert.assertNotNull("No alternate-uri-set property", alternateUriSet); Assert.assertTrue("Found hrefs for alternate-uri-set", alternateUriSet.getHrefs().isEmpty()); // 4.2 PrincipalUrl principalUrl = (PrincipalUrl) p.getProperty(PRINCIPALURL); Assert.assertNotNull("No principal-URL property", principalUrl); Assert.assertEquals("principal-URL value not the same as locator href", p.getResourceLocator().getHref(false), principalUrl.getHref()); // 4.4 GroupMembership groupMembership = (GroupMembership) p.getProperty(GROUPMEMBERSHIP); Assert.assertNotNull("No group-membership property", groupMembership); Assert.assertTrue("Found hrefs for group-membership", groupMembership.getHrefs().isEmpty()); }
From source file:org.wso2.caching.policy.CachingPolicyProcessor.java
private static void handlePolicyComponents(CacheConfiguration cacheConfig, Collection topLevelAssertionList) throws CachingException { for (Iterator topLevelAssertionsIterator = topLevelAssertionList.iterator(); topLevelAssertionsIterator .hasNext();) {//from www .java2 s. c om Object topLevelAssertionObject = topLevelAssertionsIterator.next(); if (topLevelAssertionObject instanceof Policy) { Policy policy = (Policy) topLevelAssertionObject; Collection policyComponents = policy.getPolicyComponents(); handlePolicyComponents(cacheConfig, policyComponents); } else if (topLevelAssertionObject instanceof ExactlyOne) { ExactlyOne eo = (ExactlyOne) topLevelAssertionObject; handlePolicyComponents(cacheConfig, eo.getPolicyComponents()); } else if (topLevelAssertionObject instanceof All) { All all = (All) topLevelAssertionObject; handlePolicyComponents(cacheConfig, all.getPolicyComponents()); } else if (topLevelAssertionObject instanceof XmlPrimtiveAssertion) { // Validating the policy XmlPrimtiveAssertion topLevelXmlPrimtiveAssertion = (XmlPrimtiveAssertion) topLevelAssertionObject; QName qName = topLevelXmlPrimtiveAssertion.getName(); // validating the Caching assertion if (qName.equals(CachingConstants.CACHING_ASSERTION_QNAME)) { Policy cachingPolicyComponent = PolicyEngine.getPolicy(topLevelXmlPrimtiveAssertion.getValue()); List assertionList = cachingPolicyComponent.getPolicyComponents(); for (Iterator configDataAssertionIterator = assertionList .iterator(); configDataAssertionIterator.hasNext();) { Object aConfigDataAssertionObject = configDataAssertionIterator.next(); // Validating the caching policy if (aConfigDataAssertionObject instanceof Policy) { long expireTime; DigestGenerator digestGenerator; int maxMessageSize; int maxCacheSize; Policy cachingPolicy = (Policy) aConfigDataAssertionObject; List childAssertionsList = cachingPolicy.getPolicyComponents(); for (Iterator childAssertionSIterator = childAssertionsList .iterator(); childAssertionSIterator.hasNext();) { Object configData = childAssertionSIterator.next(); if (configData instanceof All) { All all = (All) configData; List configDataList = all.getPolicyComponents(); for (Iterator configIterator = configDataList.iterator(); configIterator .hasNext();) { Object configDtaObject = configIterator.next(); if (configDtaObject instanceof XmlPrimtiveAssertion) { XmlPrimtiveAssertion cachingPrimtiveAssertion = (XmlPrimtiveAssertion) configDtaObject; //todo : break the processing // Is Identifier specified? if (cachingPrimtiveAssertion.getName() .equals(CachingConstants.CACHING_XML_IDENTIFIER_QNAME)) { String value = cachingPrimtiveAssertion.getValue().getText(); try { // Loading the class using Reflection digestGenerator = (DigestGenerator) Class.forName(value) .newInstance(); cacheConfig.setDigestGenerator(digestGenerator); } catch (ClassNotFoundException e) { handleException("Unable to find the " + "DigestGenerator implementation \"" + value + "\"", e); } catch (IllegalAccessException e) { handleException("Unable to load the " + "DigestGenerator implementation \"" + value + "\"", e); } catch (InstantiationException e) { handleException("Unable to instantiate the " + "DigestGenerator implementation \"" + value + "\"", e); } } // Is expiration time specified? if (cachingPrimtiveAssertion.getName() .equals(CachingConstants.CACHE_EXPIRATION_TIME_QNAME) && cachingPrimtiveAssertion.getValue() != null) { expireTime = Long .parseLong(cachingPrimtiveAssertion.getValue().getText()); cacheConfig.setTimeout(expireTime); } // Is max message size specified? if (cachingPrimtiveAssertion.getName() .equals(CachingConstants.MAX_MESSAGE_SIZE_QNAME) && cachingPrimtiveAssertion.getValue() != null) { maxMessageSize = Integer .parseInt(cachingPrimtiveAssertion.getValue().getText()); cacheConfig.setMaxMessageSize(maxMessageSize); } // Is max cache size specified? if (cachingPrimtiveAssertion.getName() .equals(CachingConstants.MAX_CACHE_SIZE_QNAME) && cachingPrimtiveAssertion.getValue() != null) { maxCacheSize = Integer .parseInt(cachingPrimtiveAssertion.getValue().getText()); cacheConfig.setMaxCacheSize(maxCacheSize); } } else { // invalid caching policy handleException("Unexpected caching policy " + "assertion for the caching module"); } } } else { // caching policy All not found handleException("Unexpected caching " + "policy, \"wsp:All\" expected"); } } } else { // handle policy } } } } else { // handle top level } } }
From source file:org.wso2.carbon.caching.CachingPolicyUtils.java
/** * Retrieves the four primitive caching assertions from the given caching policy component. * * @param cachingPolicyComponent the caching policy component. * @return an <code>XmlPrimtiveAssertion</code> array containing the four caching assertions. *//*from w w w.j a v a2 s .co m*/ public XmlPrimtiveAssertion[] retrieveConfigPrimitiveAssertions(Policy cachingPolicyComponent) { XmlPrimtiveAssertion[] assertionArr = new XmlPrimtiveAssertion[4]; XmlPrimtiveAssertion primitiveAssertion; QName assertionName; for (Object policyObject : cachingPolicyComponent.getPolicyComponents()) { if (policyObject instanceof Policy) { for (Object allObject : ((Policy) policyObject).getPolicyComponents()) { if (allObject instanceof All) { for (Object assertionObject : ((All) allObject).getPolicyComponents()) { if (assertionObject instanceof XmlPrimtiveAssertion) { primitiveAssertion = (XmlPrimtiveAssertion) assertionObject; if ((assertionName = primitiveAssertion.getName()) .equals(CachingComponentConstants.XML_IDENTIFIER_QNAME)) { assertionArr[0] = primitiveAssertion; } else if (assertionName .equals(CachingComponentConstants.CACHE_EXPIRATION_TIME_QNAME)) { assertionArr[1] = primitiveAssertion; } else if (assertionName.equals(CachingComponentConstants.MAX_CACHE_SIZE_QNAME)) { assertionArr[2] = primitiveAssertion; } else if (assertionName.equals(CachingComponentConstants.MAX_MESSAGE_SIZE_QNAME)) { assertionArr[3] = primitiveAssertion; } } } } } } } return assertionArr; }
From source file:org.wso2.carbon.discovery.DiscoveryOMUtils.java
private static void validateTopElement(QName expected, OMElement elt) throws DiscoveryException { QName found = elt.getQName(); if (!expected.equals(found)) { String msg = "Invalid top level element in the " + expected.getLocalPart() + " " + "message. Expected: " + expected + " but found: " + found; log.error(msg);/*from w w w . j a va 2 s .c o m*/ throw new DiscoveryException(msg); } }
From source file:org.wso2.carbon.governance.api.common.GovernanceArtifactManager.java
/** * Updates the given artifact on the registry. * @param artifact the artifact.//from w w w . j av a 2 s . c om * * @throws GovernanceException if the operation failed. */ public void updateGovernanceArtifact(GovernanceArtifact artifact) throws GovernanceException { boolean succeeded = false; try { registry.beginTransaction(); String artifactName = artifact.getQName().getLocalPart(); if (artifactNameAttribute != null) { if (StringUtils.isNotEmpty(artifactName)) { artifact.setAttributes(artifactNameAttribute, new String[] { artifactName }); } else { artifactName = artifact.getAttribute(artifactNameAttribute); } } String namespace = artifact.getQName().getNamespaceURI(); if (artifactNamespaceAttribute != null && StringUtils.isNotEmpty(namespace)) { artifact.setAttributes(artifactNamespaceAttribute, new String[] { namespace }); } else if (artifactNamespaceAttribute != null) { namespace = artifact.getAttribute(artifactNamespaceAttribute); } setQName(artifact, artifactName, namespace); validateArtifact(artifact); GovernanceArtifact oldArtifact = getGovernanceArtifact(artifact.getId()); // first check for the old artifact and remove it. String oldPath = null; if (oldArtifact != null) { QName oldName = oldArtifact.getQName(); if (!oldName.equals(artifact.getQName())) { String temp = oldArtifact.getPath(); // then it is analogue to moving the resource for the new location // so just delete the old path registry.delete(temp); } else { oldPath = oldArtifact.getPath(); } } else { throw new GovernanceException("No artifact found for the artifact id :" + artifact.getId() + "."); } String artifactId = artifact.getId(); Resource resource = registry.newResource(); resource.setMediaType(mediaType); setContent(artifact, resource); String path; if (oldPath != null) { path = oldPath; } else { path = GovernanceUtils.getPathFromPathExpression(pathExpression, artifact); } if (registry.resourceExists(path)) { Resource oldResource = registry.get(path); Properties properties = (Properties) oldResource.getProperties().clone(); // first clone existing properties resource.setProperties(properties); // then set updated properties // Stop the attributes been added as properties /*String[] attributeKeys = artifact.getAttributeKeys(); if (attributeKeys != null) { for (String aggregatedKey : attributeKeys) { if (!aggregatedKey.equals(artifactNameAttribute) && !aggregatedKey.equals(artifactNamespaceAttribute)) { resource.setProperty(aggregatedKey, Arrays.asList(artifact.getAttributes(aggregatedKey))); } } }*/ //persisting resource description at artifact update String description = oldResource.getDescription(); if (description != null) { resource.setDescription(description); } String oldContent; Object content = oldResource.getContent(); if (content instanceof String) { oldContent = (String) content; } else { oldContent = new String((byte[]) content); } String newContent; content = resource.getContent(); if (content instanceof String) { newContent = (String) content; } else { newContent = new String((byte[]) content); } if (newContent.equals(oldContent)) { artifact.setId(oldResource.getUUID()); addRelationships(path, artifact); succeeded = true; return; } } resource.setUUID(artifactId); registry.put(path, resource); // artifact.setId(resource.getUUID()); //This is done to get the UUID of a existing resource. addRelationships(path, artifact); ((GovernanceArtifactImpl) artifact).updatePath(artifactId); succeeded = true; } catch (RegistryException e) { if (e instanceof GovernanceException) { throw (GovernanceException) e; } String msg; if (artifact.getPath() != null) { msg = "Error in updating the artifact, artifact id: " + artifact.getId() + ", artifact path: " + artifact.getPath() + "." + e.getMessage() + "."; } else { msg = "Error in updating the artifact, artifact id: " + artifact.getId() + "." + e.getMessage() + "."; } log.error(msg, e); throw new GovernanceException(msg, e); } finally { if (succeeded) { try { registry.commitTransaction(); } catch (RegistryException e) { String msg; if (artifact.getPath() != null) { msg = "Error in committing transactions. Update artifact failed: artifact " + "id: " + artifact.getId() + ", path: " + artifact.getPath() + "."; } else { msg = "Error in committing transactions. Update artifact failed: artifact " + "id: " + artifact.getId() + "."; } log.error(msg, e); } } else { try { registry.rollbackTransaction(); } catch (RegistryException e) { String msg = "Error in rolling back transactions. Update artifact failed: " + "artifact id: " + artifact.getId() + ", path: " + artifact.getPath() + "."; log.error(msg, e); } } } }
From source file:org.wso2.carbon.mediation.throttle.service.ThrottleConfigAdminService.java
/** * Check whether there exists a policy for throttling within current policies * for services//w w w. j a v a 2 s. c o m * * @param components - all policy components * @return policy assertion if found, else null * @throws AxisFault - error accessing axisConfig */ private XmlPrimtiveAssertion getThrottlePolicy(Collection components) throws AxisFault { //get all policy components QName assertionName; //Finds the policy for throttling for (Object comp : components) { if (comp instanceof Policy) { Policy policy = (Policy) comp; for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) { Object object = iterator.next(); if (object instanceof List) { List list = (List) object; for (Object assertObj : list) { if (assertObj instanceof XmlPrimtiveAssertion) { XmlPrimtiveAssertion primitiveAssertion = (XmlPrimtiveAssertion) assertObj; assertionName = primitiveAssertion.getName(); if (assertionName.equals(ThrottleConstants.SERVICE_THROTTLE_ASSERTION_QNAME) || assertionName.equals(ThrottleConstants.MODULE_THROTTLE_ASSERTION_QNAME) || assertionName .equals(ThrottleConstants.OPERATION_THROTTLE_ASSERTION_QNAME) || assertionName.equals(ThrottleConstants.MEDIATOR_THROTTLE_ASSERTION_QNAME) || assertionName.equals(ThrottleConstants.THROTTLE_ASSERTION_QNAME)) { if (log.isDebugEnabled()) { log.debug("Existing ThrottleAssertion found"); } this.policyToUpdate = policy; return primitiveAssertion; } } } } } } } return null; }