/** * @param xpath XPATH expression to be read. * @param elt OMElement to be used for the search. * @return List matching OMNode list */ @SuppressWarnings("unchecked") public List<OMNode> getMatchingNodes(final String xpath, final OMElement elt) { AXIOMXPath axiomXpath; List<OMNode> nodeList = null; try { axiomXpath = new AXIOMXPath(xpath); nodeList = axiomXpath.selectNodes(elt); } catch (JaxenException e) { String msg = "Error occurred while reading the Xpath (" + xpath + ")"; log.error(msg, e); throw new CloudControllerException(msg, e); } return nodeList; }
/* * This method is used to capture the lifecycle attribute from the configuration. * * expected configuration elements are * * <field type="options"> <name label="Lifecycle Name" >Lifecycle Name</name> <values class="org.wso2.carbon.governance.generic.ui.utils.LifecycleListPopulator"/> </field> * * or * * <field type="options"> <name label="Lifecycle Name" >Lifecycle Name</name> <values class="com.foo.bar.LifecycleListPopulator" isLifecycle="true"/> </field> * */ private static String BuilLifecycleAttribute( GovernanceArtifactConfiguration configuration, String defaultLifecycleGeneratorClass, String lifecycleAttribute) { try { // This part checks whether the user has given a lifecycle populates. // If not, then we check whether there is an attribute called, "isLifecycle" // This attribute will identify the lifecycle attribute from the configuration. OMElement configurationElement = configuration.getContentDefinition(); String xpathExpression = "//@class"; AXIOMXPath xpath = new AXIOMXPath(xpathExpression); List resultNodes = xpath.selectNodes(configurationElement); if (resultNodes != null && resultNodes.size() > 0) { String lifecycleParentName = null; String lifecycleName = null; for (Object resultNode : resultNodes) { OMElement parentElement = ((OMAttribute) resultNode).getOwner(); if (parentElement .getAttributeValue(new QName("class")) .equals(defaultLifecycleGeneratorClass)) { Iterator childrenIterator = parentElement.getParent().getChildrenWithLocalName("name"); while (childrenIterator.hasNext()) { OMElement next = (OMElement) childrenIterator.next(); lifecycleName = next.getAttributeValue(new QName("label")); } OMElement rootElement = (OMElement) ((OMElement) parentElement.getParent()).getParent(); lifecycleParentName = rootElement.getAttributeValue(new QName("name")); break; } else if (parentElement.getAttributeValue(new QName("isLifecycle")) != null && parentElement.getAttributeValue(new QName("isLifecycle")).equals("true")) { Iterator childrenIterator = parentElement.getParent().getChildrenWithLocalName("name"); while (childrenIterator.hasNext()) { OMElement next = (OMElement) childrenIterator.next(); lifecycleName = next.getAttributeValue(new QName("label")); } OMElement rootElement = (OMElement) ((OMElement) parentElement.getParent()).getParent(); lifecycleParentName = rootElement.getAttributeValue(new QName("name")); break; } } if (lifecycleParentName != null && lifecycleName != null) { return convertName(lifecycleParentName.split(" ")) + "_" + convertName(lifecycleName.split(" ")); } } } catch (OMException e) { log.error( "Governance artifact configuration of configuration key:" + configuration.getKey() + " is invalid", e); } catch (JaxenException e) { log.error("Error in getting the lifecycle attribute", e); } return null; }