/** * Find the current dasextension::query::sites element or create a new one in the proper place in * the given dasextension element. * * @param dasExt - mandatory - must be a valid dasextension Element * @return */ public ExtensibleElement getSites(ExtensibleElement dasExt) { // get reference to the dasextension::query element in feed ExtensibleElement query = this.getQuery(dasExt); // get reference to the dasextension::query::sites element in feed QName sitesQname = new QName(this.dasextensionNamespace, "sites"); ExtensibleElement sites = query.getExtension(sitesQname); if (NullChecker.isEmpty(sites)) { ExtensibleElement queryFirstChild = query.getFirstChild(); if (NullChecker.isEmpty(queryFirstChild)) { // no children in query, so merely add sites element sites = query.addExtension(sitesQname); } else { QName fCQname = queryFirstChild.getQName(); if ("parameters".equals(fCQname.getLocalPart())) { ExtensibleElement querySecondChild = query.getNextSibling(); if (NullChecker.isEmpty(querySecondChild)) { // no second child in query, so add sites after parameters sites = query.addExtension(sitesQname); } else { // add sites after parameters, and before the second child QName sCQname = querySecondChild.getQName(); sites = query.addExtension(sitesQname, sCQname); } } else { // another element besides parameters is first child, // so add sites before this sites = dasExt.addExtension(sitesQname, fCQname); } } } return sites; }
/** * Find the current dasextension::query element or create a new one in the proper place in the * given dasextension element. * * @param dasExt - mandatory - must be a valid dasextension Element * @return */ private ExtensibleElement getQuery(ExtensibleElement dasExt) { QName queryQname = new QName(this.dasextensionNamespace, "query"); // attempt to get query element ExtensibleElement query = dasExt.getExtension(queryQname); if (NullChecker.isEmpty(query)) { // there is no query element, so create one in the proper place ExtensibleElement firstChild = dasExt.getFirstChild(); if (NullChecker.isEmpty(firstChild)) { // no children, so merely add query query = dasExt.addExtension(queryQname); } else { QName fCQname = firstChild.getQName(); if ("path".equals(fCQname.getLocalPart())) { // path is the firstChild, so get the second child ExtensibleElement secondChild = firstChild.getNextSibling(); if (NullChecker.isEmpty(secondChild)) { // no second child, so add query after path query = dasExt.addExtension(queryQname); } else { QName sCQname = secondChild.getQName(); // have a second child, so add query after // path element and before second child query = dasExt.addExtension(queryQname, sCQname); } } else { // add query before the first child element query = dasExt.addExtension(queryQname, fCQname); } } } return query; }
/** * Add an new empty feed::dasextension element with only a completed management element to the * given Feed. Sets the responseTime value to now. Note: A proper sites::site element must be * added to the new feed::dasextension element for this new feed::dasextension element to be * valid. * * @param feed - mandatory * @return */ private Feed addEmptyDasExtension(Feed feed) { // check to make sure there's a dasextension QName dasextensionQname = new QName(this.dasextensionNamespace, "dasextension"); ExtensibleElement dasExt = feed.getExtension(dasextensionQname); if (NullChecker.isEmpty(dasExt)) { dasExt = feed.addExtension(dasextensionQname); // add the dasextension::management element QName managementQname = new QName(this.dasextensionNamespace, "management"); ExtensibleElement management = dasExt.getExtension(managementQname); if (NullChecker.isEmpty(management)) { management = dasExt.addExtension(managementQname); } QName responseTimeQname = new QName(this.dasextensionNamespace, "responseTime"); ExtensibleElement responseTime = management.getExtension(responseTimeQname); if (NullChecker.isEmpty(responseTime)) { responseTime = management.addExtension(responseTimeQname); } // set/reset the response time to now XMLGregorianCalendar xmlGregCalResponseTime = GregorianDateUtil.getGregorianCalendarByDate(new Date()); responseTime.setText(xmlGregCalResponseTime.toString()); // TODO: Verify date format } return feed; }
@Override public String get(String arg0) { CustomProfileValueSource.LOG.debug( "Value of " + this.testProp + " is " + this.sysProps.getProperty(this.testProp)); final String value = this.sysProps.getProperty(this.testProp); if (NullChecker.isEmpty(value)) { return "all"; } else { return value; } }
/** * Find the current dasextension::query::errors element or create a new one in the proper place in * the given dasextension element. * * @param dasExt - mandatory - must be a valid dasextension Element * @return */ public ExtensibleElement getErrors(ExtensibleElement dasExt) { // get reference to the dasextension::query element in feed ExtensibleElement query = this.getQuery(dasExt); // get reference to the dasextension::query::errors element in feed QName errorsQname = new QName(this.dasextensionNamespace, "errors"); ExtensibleElement errors = query.getExtension(errorsQname); if (NullChecker.isEmpty(errors)) { List<Element> queryChildren = query.getElements(); if (NullChecker.isEmpty(queryChildren)) { // no children in query, so merely add errors element errors = query.addExtension(errorsQname); } else { // add errors after the last child errors = query.addExtension(errorsQname); } } return errors; }
@Override public Object transform(final Object src) throws TransformerException { if (NullChecker.isEmpty(this.transformers)) { return src; } Object value = src; for (final Transformer<Object, Object> transformer : this.transformers) { value = transformer.transform(value); } return value; }
@Override public final boolean validate(final Document message) throws ValidatorException { Assert.assertNotEmpty(message, "Message cannot be null!"); try { for (final XPathExpression expression : this.xPathExpressions) { final java.lang.Boolean booleanValue = (java.lang.Boolean) expression.evaluate(message, XPathConstants.BOOLEAN); if (NullChecker.isEmpty(booleanValue) || !booleanValue) { return false; } } return true; } catch (final XPathException e) { throw new ValidatorException(e); } }
/** * Find the current dasextension::query::parameters element or create a new one in the proper * place in the given dasextension element. * * @param dasExt - mandatory - must be a valid dasextension Element * @return */ private ExtensibleElement getQueryParameters(ExtensibleElement dasExt) { QName parametersQname = new QName(this.dasextensionNamespace, "parameters"); ExtensibleElement parameters = null; ExtensibleElement query = this.getQuery(dasExt); ExtensibleElement queryFirstChild = query.getFirstChild(); if (NullChecker.isEmpty(queryFirstChild)) { // no children in query, so just query::parameters parameters = query.addExtension(parametersQname); } else { QName fCQname = queryFirstChild.getQName(); if ("parameters".equals(fCQname.getLocalPart())) { // already have a query::parameters parameters = queryFirstChild; } else { // firstQueryChild is not parameters, so add query::parameters before it parameters = query.addExtension(parametersQname, fCQname); } } return parameters; }