/** * 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; }
/** * Find the current dasextension::path::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 getPathParameters(ExtensibleElement dasExt) { QName parametersQname = new QName(this.dasextensionNamespace, "parameters"); ExtensibleElement parameters = null; ExtensibleElement path = this.getPath(dasExt); ExtensibleElement pathFirstChild = path.getFirstChild(); if (NullChecker.isNotEmpty(pathFirstChild)) { // already have a parameters parameters = pathFirstChild; } else { // no parameters, so add one parameters = path.addExtension(parametersQname); } return parameters; }
/** * Find the current dasextension::path element or create a new one in the proper place in the * given dasextension element. * * @param dasExt - must be a valid dasextension Element * @return */ private ExtensibleElement getPath(ExtensibleElement dasExt) { // get or create a reference to the dasextension::path element in feed QName pathQname = new QName(this.dasextensionNamespace, "path"); ExtensibleElement path = null; ExtensibleElement firstChild = (ExtensibleElement) dasExt.getFirstChild(); if (NullChecker.isNotEmpty(firstChild)) { QName fCQname = firstChild.getQName(); if ("path".equals(fCQname.getLocalPart())) { // path is the firstChild path = firstChild; } else { // no path, so add it before firstChild path = dasExt.addExtension(pathQname, fCQname); } } else { // no children, so create a "path" element path = dasExt.addExtension(pathQname); } return path; }
/** * 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; }