Example usage for org.w3c.dom Element getNodeName

List of usage examples for org.w3c.dom Element getNodeName

Introduction

In this page you can find the example usage for org.w3c.dom Element getNodeName.

Prototype

public String getNodeName();

Source Link

Document

The name of this node, depending on its type; see the table above.

Usage

From source file:com.alfaariss.oa.engine.core.Engine.java

/**
 * Creates an instance of the Component.
 * /*from  w  w w .j  a v a2  s . com*/
 * Returns the new <code>IComponent</code> implementation or 
 * <code>null</code> if the new component implementation is equal to the 
 * current component.
 *
 * @param eConfig the base configuration section where the component 
 *  config can be found
 * @param oOrigionalComponent The origional component
 * @return the component as IComponent
 * @throws OAException if component can't be created
 */
private IComponent getComponent(Element eConfig, IComponent oOrigionalComponent) throws OAException {
    IComponent component = null;
    try {
        String sClass = _configurationManager.getParam(eConfig, "class");
        if (sClass == null) {
            _logger.error(eConfig.getNodeName() + " implementation class parameter not found");
            throw new OAException(SystemErrors.ERROR_CONFIG_READ);
        }

        Class oClass = null;
        try {
            oClass = Class.forName(sClass);
        } catch (ClassNotFoundException e) {
            _logger.error("Configured class doesn't exist: " + sClass, e);
            throw new OAException(SystemErrors.ERROR_CONFIG_READ);
        }

        if (oOrigionalComponent != null && oClass.equals(oOrigionalComponent.getClass()))
            return null;

        try {
            component = (IComponent) oClass.newInstance();
        } catch (InstantiationException e) {
            _logger.error("Can't create an instance of the configured class: " + sClass, e);
            throw new OAException(SystemErrors.ERROR_CONFIG_READ);
        } catch (IllegalAccessException e) {
            _logger.error("Configured class can't be accessed: " + sClass, e);
            throw new OAException(SystemErrors.ERROR_CONFIG_READ);
        } catch (ClassCastException e) {
            _logger.error("Configured class isn't of type 'IComponent': " + sClass, e);
            throw new OAException(SystemErrors.ERROR_CONFIG_READ);
        }
    } catch (OAException e) {
        throw e;
    } catch (Exception e) {
        _logger.fatal("Internal error during the component retrieval: " + eConfig.getNodeName(), e);
        throw new OAException(SystemErrors.ERROR_INTERNAL);
    }

    return component;
}

From source file:com.opensymphony.xwork3.config.providers.XmlConfigurationProvider.java

public void register() throws ConfigurationException {
    if (LOG.isInfoEnabled()) {
        LOG.info("Parsing configuration file [" + configFileName + "]");
    }//from ww  w . j  a  v  a2s  .co  m
    Map<String, Node> loadedBeans = new HashMap<String, Node>();
    for (Document doc : documents) {
        Element rootElement = doc.getDocumentElement();
        NodeList children = rootElement.getChildNodes();
        int childSize = children.getLength();

        for (int i = 0; i < childSize; i++) {
            Node childNode = children.item(i);

            if (childNode instanceof Element) {
                Element child = (Element) childNode;

                final String nodeName = child.getNodeName();

                if ("bean".equals(nodeName)) {
                    //                        String type = child.getAttribute("type");
                    String name = child.getAttribute("name");
                    String impl = child.getAttribute("class");
                    try {
                        Container.getInstance().getBeans().put(name, objectFactory.buildBean(impl, null));
                    } catch (Exception e) {
                        throw new ConfigurationException(e.getMessage());
                    }
                    /*String onlyStatic = child.getAttribute("static");
                    String scopeStr = child.getAttribute("scope");
                    boolean optional = "true".equals(child.getAttribute("optional"));
                    Scope scope = Scope.SINGLETON;
                    if ("default".equals(scopeStr)) {
                    scope = Scope.DEFAULT;
                    } else if ("request".equals(scopeStr)) {
                    scope = Scope.REQUEST;
                    } else if ("session".equals(scopeStr)) {
                    scope = Scope.SESSION;
                    } else if ("singleton".equals(scopeStr)) {
                    scope = Scope.SINGLETON;
                    } else if ("thread".equals(scopeStr)) {
                    scope = Scope.THREAD;
                    }*/

                    /*if (StringUtils.isEmpty(name)) {
                    name = Container.DEFAULT_NAME;
                    }
                            
                    try {
                    Class cimpl = ClassLoaderUtil.loadClass(impl, getClass());
                    Class ctype = cimpl;
                    if (StringUtils.isNotEmpty(type)) {
                        ctype = ClassLoaderUtil.loadClass(type, getClass());
                    }
                    if ("true".equals(onlyStatic)) {
                        // Force loading of class to detect no class def found exceptions
                        cimpl.getDeclaredClasses();
                        containerBuilder.injectStatics(cimpl);
                    } else {
                        if (containerBuilder.contains(ctype, name)) {
                            Location loc = LocationUtils.getLocation(loadedBeans.get(ctype.getName() + name));
                            if (throwExceptionOnDuplicateBeans) {
                                throw new ConfigurationException("Bean type " + ctype + " with the name " +
                                        name + " has already been loaded by " + loc, child);
                            }
                        }
                            
                        // Force loading of class to detect no class def found exceptions
                        cimpl.getDeclaredConstructors();
                            
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Loaded type:" + type + " name:" + name + " impl:" + impl);
                        }
                        containerBuilder.factory(ctype, name, new LocatableFactory(name, ctype, cimpl, scope, childNode), scope);
                    }
                    loadedBeans.put(ctype.getName() + name, child);
                    } catch (Throwable ex) {
                    if (!optional) {
                        throw new ConfigurationException("Unable to load bean: type:" + type + " class:" + impl, ex, childNode);
                    } else {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Unable to load optional class: #0", impl);
                        }
                    }
                    }*/
                } else if ("constant".equals(nodeName)) {
                    String name = child.getAttribute("name");
                    String value = child.getAttribute("value");
                    Container.getInstance().getConstants().put(name, value);
                    //                        props.setProperty(name, value, childNode);
                } /*else if (nodeName.equals("unknown-handler-stack")) {
                  List<UnknownHandlerConfig> unknownHandlerStack = new ArrayList<UnknownHandlerConfig>();
                  NodeList unknownHandlers = child.getElementsByTagName("unknown-handler-ref");
                  int unknownHandlersSize = unknownHandlers.getLength();
                          
                  for (int k = 0; k < unknownHandlersSize; k++) {
                      Element unknownHandler = (Element) unknownHandlers.item(k);
                      unknownHandlerStack.add(new UnknownHandlerConfig(unknownHandler.getAttribute("name")));
                  }
                          
                  if (!unknownHandlerStack.isEmpty())
                      configuration.setUnknownHandlerStack(unknownHandlerStack);
                  }*/
            }
        }
    }
}

From source file:com.opensymphony.xwork3.config.providers.XmlConfigurationProvider.java

private List<Document> loadConfigurationFiles(String fileName, Element includeElement) {
    List<Document> docs = new ArrayList<Document>();
    List<Document> finalDocs = new ArrayList<Document>();
    if (!includedFileNames.contains(fileName)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Loading action configurations from: " + fileName);
        }/*from  w w w.j  ava2 s .  c o m*/

        includedFileNames.add(fileName);

        Iterator<URL> urls = null;
        InputStream is = null;

        IOException ioException = null;
        try {
            urls = getConfigurationUrls(fileName);
        } catch (IOException ex) {
            ioException = ex;
        }

        if (urls == null || !urls.hasNext()) {
            if (errorIfMissing) {
                throw new ConfigurationException("Could not open files of the name " + fileName, ioException);
            } else {
                if (LOG.isInfoEnabled()) {
                    LOG.info("Unable to locate configuration files of the name " + fileName + ", skipping");
                }
                return docs;
            }
        }

        URL url = null;
        while (urls.hasNext()) {
            try {
                url = urls.next();
                is = fileManager.loadFile(url);

                InputSource in = new InputSource(is);

                in.setSystemId(url.toString());

                docs.add(DomHelper.parse(in, dtdMappings));
            } /*catch (XWorkException e) {
              if (includeElement != null) {
                  throw new ConfigurationException("Unable to load " + url, e);
              } else {
                  throw new ConfigurationException("Unable to load " + url, e);
              }
              } */catch (Exception e) {
                throw new ConfigurationException("Caught exception while loading file " + fileName, e);
            } finally {
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException e) {
                        LOG.error("Unable to close input stream", e);
                    }
                }
            }
        }

        //sort the documents, according to the "order" attribute
        Collections.sort(docs, new Comparator<Document>() {
            public int compare(Document doc1, Document doc2) {
                return XmlHelper.getLoadOrder(doc1).compareTo(XmlHelper.getLoadOrder(doc2));
            }
        });

        for (Document doc : docs) {
            Element rootElement = doc.getDocumentElement();
            NodeList children = rootElement.getChildNodes();
            int childSize = children.getLength();

            for (int i = 0; i < childSize; i++) {
                Node childNode = children.item(i);

                if (childNode instanceof Element) {
                    Element child = (Element) childNode;

                    final String nodeName = child.getNodeName();

                    if ("include".equals(nodeName)) {
                        String includeFileName = child.getAttribute("file");
                        if (includeFileName.indexOf('*') != -1) {
                            // handleWildCardIncludes(includeFileName, docs, child);
                            ClassPathFinder wildcardFinder = new ClassPathFinder();
                            wildcardFinder.setPattern(includeFileName);
                            Vector<String> wildcardMatches = wildcardFinder.findMatches();
                            for (String match : wildcardMatches) {
                                finalDocs.addAll(loadConfigurationFiles(match, child));
                            }
                        } else {
                            finalDocs.addAll(loadConfigurationFiles(includeFileName, child));
                        }
                    }
                }
            }
            finalDocs.add(doc);
            loadedFileUrls.add(url.toString());
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("Loaded action configuration from: " + fileName);
        }
    }
    return finalDocs;
}

From source file:com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.java

public void register(ContainerBuilder containerBuilder, LocatableProperties props)
        throws ConfigurationException {
    if (LOG.isInfoEnabled()) {
        LOG.info("Parsing configuration file [" + configFileName + "]");
    }/*from w  w w.j a  v a2s .com*/
    Map<String, Node> loadedBeans = new HashMap<String, Node>();
    for (Document doc : documents) {
        Element rootElement = doc.getDocumentElement();
        NodeList children = rootElement.getChildNodes();
        int childSize = children.getLength();

        for (int i = 0; i < childSize; i++) {
            Node childNode = children.item(i);

            if (childNode instanceof Element) {
                Element child = (Element) childNode;

                final String nodeName = child.getNodeName();

                if ("bean".equals(nodeName)) {
                    String type = child.getAttribute("type");
                    String name = child.getAttribute("name");
                    String impl = child.getAttribute("class");
                    String onlyStatic = child.getAttribute("static");
                    String scopeStr = child.getAttribute("scope");
                    boolean optional = "true".equals(child.getAttribute("optional"));
                    Scope scope = Scope.SINGLETON;
                    if ("default".equals(scopeStr)) {
                        scope = Scope.DEFAULT;
                    } else if ("request".equals(scopeStr)) {
                        scope = Scope.REQUEST;
                    } else if ("session".equals(scopeStr)) {
                        scope = Scope.SESSION;
                    } else if ("singleton".equals(scopeStr)) {
                        scope = Scope.SINGLETON;
                    } else if ("thread".equals(scopeStr)) {
                        scope = Scope.THREAD;
                    }

                    if (StringUtils.isEmpty(name)) {
                        name = Container.DEFAULT_NAME;
                    }

                    try {
                        Class cimpl = ClassLoaderUtil.loadClass(impl, getClass());
                        Class ctype = cimpl;
                        if (StringUtils.isNotEmpty(type)) {
                            ctype = ClassLoaderUtil.loadClass(type, getClass());
                        }
                        if ("true".equals(onlyStatic)) {
                            // Force loading of class to detect no class def found exceptions
                            cimpl.getDeclaredClasses();
                            containerBuilder.injectStatics(cimpl);
                        } else {
                            if (containerBuilder.contains(ctype, name)) {
                                Location loc = LocationUtils
                                        .getLocation(loadedBeans.get(ctype.getName() + name));
                                if (throwExceptionOnDuplicateBeans) {
                                    throw new ConfigurationException("Bean type " + ctype + " with the name "
                                            + name + " has already been loaded by " + loc, child);
                                }
                            }

                            // Force loading of class to detect no class def found exceptions
                            cimpl.getDeclaredConstructors();

                            if (LOG.isDebugEnabled()) {
                                LOG.debug("Loaded type:" + type + " name:" + name + " impl:" + impl);
                            }
                            containerBuilder.factory(ctype, name,
                                    new LocatableFactory(name, ctype, cimpl, scope, childNode), scope);
                        }
                        loadedBeans.put(ctype.getName() + name, child);
                    } catch (Throwable ex) {
                        if (!optional) {
                            throw new ConfigurationException(
                                    "Unable to load bean: type:" + type + " class:" + impl, ex, childNode);
                        } else {
                            if (LOG.isDebugEnabled()) {
                                LOG.debug("Unable to load optional class: #0", impl);
                            }
                        }
                    }
                } else if ("constant".equals(nodeName)) {
                    String name = child.getAttribute("name");
                    String value = child.getAttribute("value");
                    props.setProperty(name, value, childNode);
                } else if (nodeName.equals("unknown-handler-stack")) {
                    List<UnknownHandlerConfig> unknownHandlerStack = new ArrayList<UnknownHandlerConfig>();
                    NodeList unknownHandlers = child.getElementsByTagName("unknown-handler-ref");
                    int unknownHandlersSize = unknownHandlers.getLength();

                    for (int k = 0; k < unknownHandlersSize; k++) {
                        Element unknownHandler = (Element) unknownHandlers.item(k);
                        unknownHandlerStack.add(new UnknownHandlerConfig(unknownHandler.getAttribute("name")));
                    }

                    if (!unknownHandlerStack.isEmpty())
                        configuration.setUnknownHandlerStack(unknownHandlerStack);
                }
            }
        }
    }
}

From source file:com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.java

private List<Document> loadConfigurationFiles(String fileName, Element includeElement) {
    List<Document> docs = new ArrayList<Document>();
    List<Document> finalDocs = new ArrayList<Document>();
    if (!includedFileNames.contains(fileName)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Loading action configurations from: " + fileName);
        }//from ww w  .j av  a2 s. c  om

        includedFileNames.add(fileName);

        Iterator<URL> urls = null;
        InputStream is = null;

        IOException ioException = null;
        try {
            urls = getConfigurationUrls(fileName);
        } catch (IOException ex) {
            ioException = ex;
        }

        if (urls == null || !urls.hasNext()) {
            if (errorIfMissing) {
                throw new ConfigurationException("Could not open files of the name " + fileName, ioException);
            } else {
                if (LOG.isInfoEnabled()) {
                    LOG.info("Unable to locate configuration files of the name " + fileName + ", skipping");
                }
                return docs;
            }
        }

        URL url = null;
        while (urls.hasNext()) {
            try {
                url = urls.next();
                is = fileManager.loadFile(url);

                InputSource in = new InputSource(is);

                in.setSystemId(url.toString());

                docs.add(DomHelper.parse(in, dtdMappings));
            } catch (XWorkException e) {
                if (includeElement != null) {
                    throw new ConfigurationException("Unable to load " + url, e, includeElement);
                } else {
                    throw new ConfigurationException("Unable to load " + url, e);
                }
            } catch (Exception e) {
                throw new ConfigurationException("Caught exception while loading file " + fileName, e,
                        includeElement);
            } finally {
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException e) {
                        LOG.error("Unable to close input stream", e);
                    }
                }
            }
        }

        //sort the documents, according to the "order" attribute
        Collections.sort(docs, new Comparator<Document>() {
            public int compare(Document doc1, Document doc2) {
                return XmlHelper.getLoadOrder(doc1).compareTo(XmlHelper.getLoadOrder(doc2));
            }
        });

        for (Document doc : docs) {
            Element rootElement = doc.getDocumentElement();
            NodeList children = rootElement.getChildNodes();
            int childSize = children.getLength();

            for (int i = 0; i < childSize; i++) {
                Node childNode = children.item(i);

                if (childNode instanceof Element) {
                    Element child = (Element) childNode;

                    final String nodeName = child.getNodeName();

                    if ("include".equals(nodeName)) {
                        String includeFileName = child.getAttribute("file");
                        if (includeFileName.indexOf('*') != -1) {
                            // handleWildCardIncludes(includeFileName, docs, child);
                            ClassPathFinder wildcardFinder = new ClassPathFinder();
                            wildcardFinder.setPattern(includeFileName);
                            Vector<String> wildcardMatches = wildcardFinder.findMatches();
                            for (String match : wildcardMatches) {
                                finalDocs.addAll(loadConfigurationFiles(match, child));
                            }
                        } else {
                            finalDocs.addAll(loadConfigurationFiles(includeFileName, child));
                        }
                    }
                }
            }
            finalDocs.add(doc);
            loadedFileUrls.add(url.toString());
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("Loaded action configuration from: " + fileName);
        }
    }
    return finalDocs;
}

From source file:com.draagon.meta.loader.xml.XMLFileMetaDataLoader.java

/**
 * Loads the specified group types/*ww  w.  j  ava  2 s.  com*/
 */
protected void loadTypes(Element el, MetaDataTypes typesMap) throws MetaException, SAXException {

    String section = el.getNodeName();

    //Collection<Element> c = getElementsOfName(root, section);

    // Iterate through each section grouping (should just be 1)
    //for (Element el : c) {
    Collection<Element> typeCol = getElementsOfName(el, "type");

    // Iterate through each type
    for (Element typeEl : typeCol) {

        String name = typeEl.getAttribute(ATTR_NAME);
        String tclass = typeEl.getAttribute("class");

        if (name.length() == 0) {
            throw new MetaException("Type of section [" + section + "] has no 'name' attribute specified");
        }

        try {
            Class<MetaData> tcl = (Class<MetaData>) Class.forName(tclass);

            // Add the type class with the specified name
            typesMap.put(name, tcl);
        } catch (ClassNotFoundException e) {
            throw new MetaException("Type of section [" + section + "] with name [" + name
                    + "] has invalid class: " + e.getMessage());
            //log.warn( "Type of section [" + section + "] with name [" + name + "] has unknown class: " + e.getMessage() );
        }
    }
    //}
}

From source file:com.draagon.meta.loader.xml.XMLFileMetaDataLoader.java

protected void parseMetaData(String defaultPackageName, MetaData parent, Element element, boolean isRoot)
        throws SAXException {

    // Iterate through all elements
    for (Element el : getElements(element)) {

        String nodeName = el.getNodeName();

        // Get the MetaDataTypes map for this element
        MetaDataTypes types = typesMap.get(nodeName);
        if (types == null) {
            // TODO:  What is the best behavior here?
            log.warn("Ignoring '" + nodeName + "' element found on parent: " + parent);
            continue;
        }/*  www . ja v a2 s. c  o  m*/

        // Get the item name
        String name = el.getAttribute(ATTR_NAME);
        if (name == null || name.equals("")) {
            throw new MetaException("MetaData [" + nodeName + "] had no name specfied in XML");
        }

        // Get the packaging name
        String packageName = el.getAttribute("package");
        if (packageName == null || packageName.trim().length() == 0) {
            packageName = defaultPackageName;
        }

        // Load or get the MetaData
        MetaData md = null;
        boolean isNew = false;

        try {
            if (isRoot && packageName.length() > 0) {
                md = parent.getChild(packageName + PKG_SEPARATOR + name, types.baseClass);
            } else {
                md = parent.getChild(name, types.baseClass);

                // If it's not a child from the same parent, we need to wrap it
                if (md.getParent() != parent) {
                    md = md.wrap();
                    isNew = true;
                }
            }
        } catch (MetaDataNotFoundException e) {
        }

        // If this MetaData doesn't exist yet, then we need to create it
        if (md == null) {

            isNew = true;

            // Set the SuperClass if one is defined
            MetaData superData = null;
            String superStr = el.getAttribute(ATTR_SUPER);

            // If a super class was specified
            if (superStr.length() > 0) {

                // Try to find it with the name prepended if not fully qualified
                try {
                    if (superStr.indexOf(PKG_SEPARATOR) < 0 && packageName.length() > 0) {
                        superData = getMetaDataByName(types.baseClass, packageName + PKG_SEPARATOR + superStr);
                    }
                } catch (MetaObjectNotFoundException e) {
                    log.debug("Could not find MetaData [" + packageName + PKG_SEPARATOR + superStr
                            + "], assuming fully qualified");
                }

                // Try to find it by the provided name in the 'super' attribute
                if (superData == null) {
                    try {
                        superData = getMetaDataByName(types.baseClass, superStr);
                    } catch (MetaObjectNotFoundException e) {
                        log.error("Invalid MetaData [" + nodeName + "][" + md + "], the SuperClass [" + superStr
                                + "] does not exist");
                        throw new MetaException("Invalid MetaData [" + nodeName + "][" + md
                                + "], the SuperClass [" + superStr + "] does not exist");
                    }
                }
            }
            // Check to make sure people arent' defining attributes when it shouldn't
            else {
                String s = el.getAttribute(ATTR_SUPER);
                if (s == null || s.isEmpty()) {
                    log.warn("Attribute 'super' defined on MetaData [" + nodeName + "][" + name
                            + "] under parent [" + parent
                            + "], but should not be as metadata with that name already existed");
                }
            }

            // get the class reference and create the class
            String typeName = el.getAttribute(ATTR_TYPE);
            if (typeName.isEmpty())
                typeName = null;

            Class<?> c = null;
            try {
                // Attempt to load the referenced class
                if (typeName == null) {

                    // Use the Super class type if no type is defined and a super class exists
                    if (superData != null) {
                        c = superData.getClass();
                    }
                    // Default to StringAttribute if no type is defined for a MetaAttribute
                    else if (types.baseClass.isAssignableFrom(MetaAttribute.class)) {
                        c = StringAttribute.class;
                    }
                    // Default to ValueObject if no type is defined for a MetaObject
                    else if (types.baseClass.isAssignableFrom(MetaObject.class)) {
                        c = ValueMetaObject.class;
                    }
                    // Default to StringField if no type is defined for a MetaField
                    else if (types.baseClass.isAssignableFrom(MetaField.class)) {
                        c = StringField.class;
                    }
                    // Otherwise throw an error
                    else {
                        throw new MetaException(
                                "MetaData [" + nodeName + "][" + name + "] has no type defined");
                    }
                } else {
                    c = (Class<? extends MetaData>) types.get(typeName);
                    if (c == null) {
                        throw new MetaException("MetaData [" + nodeName + "] had type [" + typeName
                                + "], but it was not recognized");
                    }
                }

                // Figure out the full name for the element, needs package prefix if root
                String fullname = name;
                if (isRoot)
                    fullname = packageName + PKG_SEPARATOR + fullname;

                // Create the object
                md = (MetaData) c.getConstructor(String.class).newInstance(fullname);
            } catch (MetaException e) {
                throw e;
            } catch (Exception e) {
                log.error("Invalid MetaData [" + nodeName + "][" + c.getName() + "]: " + e.getMessage());
                throw new MetaException("Invalid MetaData [" + nodeName + "][" + c.getName() + "]", e);
            }

            // Set the name and package name
            //mc.setName( packageName + MetaData.SEPARATOR + name );
            //mc.setPackage( packageName );

            // Set the super data class if one exists
            if (superData != null) {
                md.setSuperData(superData);
            }
        }

        // Parse and set the Attributes
        //Collection<MetaAttribute> attrs = parseAttributes(el);
        //for (Iterator<MetaAttribute> j = attrs.iterator(); j.hasNext();) {
        //    md.addAttribute(j.next());
        //}

        // Parse the fields
        //parseFields(md, el);

        // Add the MetaData to the loader
        // NOTE:  Add it first to ensure the correct parent is set
        if (isNew) {
            parent.addChild(md);
        }

        // Different behavior if it's a MetaAttribute
        if (md instanceof MetaAttribute) {
            parseMetaAttributeValue((MetaAttribute) md, el);
        }

        // otherwide, parse as normal recursively
        else {
            // Parse any extra attributes
            parseAttributes(md, el);

            // Parse the sub elements
            parseMetaData(packageName, md, el, false);
        }
    }
}

From source file:com.twinsoft.convertigo.engine.util.WsReference.java

private static void extractSoapVariables(XmlSchema xmlSchema, List<RequestableHttpVariable> variables,
        Node node, String longName, boolean isMulti, QName variableType) throws EngineException {
    if (node == null)
        return;/*ww  w  . ja  v a2s  . c  o m*/
    int type = node.getNodeType();

    if (type == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        if (element != null) {
            String elementName = element.getLocalName();
            if (longName != null)
                elementName = longName + "_" + elementName;

            if (!element.getAttribute("soapenc:arrayType").equals("") && !element.hasChildNodes()) {
                String avalue = element.getAttribute("soapenc:arrayType");
                element.setAttribute("soapenc:arrayType", avalue.replaceAll("\\[\\]", "[1]"));

                Element child = element.getOwnerDocument().createElement("item");
                String atype = avalue.replaceAll("\\[\\]", "");
                child.setAttribute("xsi:type", atype);
                if (atype.startsWith("xsd:")) {
                    String variableName = elementName + "_item";
                    child.appendChild(
                            element.getOwnerDocument().createTextNode("$(" + variableName.toUpperCase() + ")"));
                    RequestableHttpVariable httpVariable = createHttpVariable(true, variableName,
                            new QName(Constants.URI_2001_SCHEMA_XSD, atype.split(":")[1]));
                    variables.add(httpVariable);
                }
                element.appendChild(child);
            }

            // extract from attributes
            NamedNodeMap map = element.getAttributes();
            for (int i = 0; i < map.getLength(); i++) {
                Node child = map.item(i);
                if (child.getNodeName().equals("soapenc:arrayType"))
                    continue;
                if (child.getNodeName().equals("xsi:type"))
                    continue;
                if (child.getNodeName().equals("soapenv:encodingStyle"))
                    continue;

                String variableName = getVariableName(variables, elementName + "_" + child.getLocalName());

                child.setNodeValue("$(" + variableName.toUpperCase() + ")");

                RequestableHttpVariable httpVariable = createHttpVariable(false, variableName,
                        Constants.XSD_STRING);
                variables.add(httpVariable);
            }

            // extract from children nodes
            boolean multi = false;
            QName qname = Constants.XSD_STRING;
            NodeList children = element.getChildNodes();
            if (children.getLength() > 0) {
                Node child = element.getFirstChild();
                while (child != null) {
                    if (child.getNodeType() == Node.COMMENT_NODE) {
                        String value = child.getNodeValue();
                        if (value.startsWith("type:")) {
                            String schemaType = child.getNodeValue().substring("type:".length()).trim();
                            qname = getVariableSchemaType(xmlSchema, schemaType);
                        }
                        if (value.indexOf("repetitions:") != -1) {
                            multi = true;
                        }
                    } else if (child.getNodeType() == Node.TEXT_NODE) {
                        String value = child.getNodeValue().trim();
                        if (value.equals("?") || !value.equals("")) {
                            String variableName = getVariableName(variables, elementName);

                            child.setNodeValue("$(" + variableName.toUpperCase() + ")");

                            RequestableHttpVariable httpVariable = createHttpVariable(isMulti, variableName,
                                    variableType);
                            variables.add(httpVariable);
                        }
                    } else if (child.getNodeType() == Node.ELEMENT_NODE) {
                        extractSoapVariables(xmlSchema, variables, child, elementName, multi, qname);
                        multi = false;
                        qname = Constants.XSD_STRING;
                    }

                    child = child.getNextSibling();
                }
            }

        }
    }
}

From source file:de.betterform.xml.xforms.model.Model.java

private void loadInlineSchemas(List list) throws XFormsException {
    String schemaId = null;/*from w w w  . j  a  v a  2 s . c o  m*/
    try {
        NodeList children = this.element.getChildNodes();

        for (int index = 0; index < children.getLength(); index++) {
            Node child = children.item(index);

            if (Node.ELEMENT_NODE == child.getNodeType()
                    && NamespaceConstants.XMLSCHEMA_NS.equals(child.getNamespaceURI())) {
                Element element = (Element) child;
                schemaId = element.hasAttributeNS(null, "id") ? element.getAttributeNS(null, "id")
                        : element.getNodeName();

                XSModel schema = loadSchema(element);

                if (schema == null) {
                    throw new NullPointerException("resource not found");
                }
                list.add(schema);
            }
        }
    } catch (Exception e) {
        throw new XFormsLinkException("could not load inline schema", e, this.target, schemaId);
    }
}

From source file:com.fota.Link.sdpApi.java

public SDPInfoVO getSpecificSubscpnInfo(String CTN) {
    //String resultStr = null;
    SDPInfoVO resVO = new SDPInfoVO();
    String strIMEI = null;//from w  w  w  .  jav  a 2 s  .co m
    String Model_Name = null;
    String return_cd = null;
    try {
        String endPointUrl = PropUtil.getPropValue("sdp.oif114.url");

        String strRequest = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' "
                + "xmlns:oas='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'"
                + " xmlns:sdp='http://kt.com/sdp'>" + "     <soapenv:Header>" + "         <oas:Security>"
                + "             <oas:UsernameToken>" + "                 <oas:Username>"
                + PropUtil.getPropValue("sdp.id") + "</oas:Username>" + "                 <oas:Password>"
                + PropUtil.getPropValue("sdp.pw") + "</oas:Password>" + "             </oas:UsernameToken>"
                + "         </oas:Security>" + "     </soapenv:Header>"

                + "     <soapenv:Body>" + "         <sdp:getSpecificSubscpnInfoRequest>"
                + "         <!--You may enterthe following 6 items in any order-->"

                // + "             <sdp:Credt_Id></sdp:Credt_Id>"
                + "             <sdp:User_Name>" + CTN + "</sdp:User_Name>" + "<sdp:Credt_Type_Cd>" + "05"

                + "</sdp:Credt_Type_Cd>"

                + "         </sdp:getSpecificSubscpnInfoRequest>\n" + "     </soapenv:Body>\n"
                + "</soapenv:Envelope>";

        // connection
        URL url = new URL(endPointUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Content-type", "text/xml;charset=utf-8");
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.connect();

        // output
        OutputStream os = connection.getOutputStream();
        // os.write(strRequest.getBytes(), 0, strRequest.length());
        os.write(strRequest.getBytes("utf-8"));
        os.flush();
        os.close();

        // input
        InputStream is = connection.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8"));
        String line = null;
        String parseStr = null;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
            parseStr = line;
        }
        //resultStr = line;
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        InputSource temp = new InputSource();
        temp.setCharacterStream(new StringReader(parseStr));
        Document doc = builder.parse(temp); //xml?

        NodeList list = doc.getElementsByTagName("*");

        int i = 0;
        Element element;
        String contents;
        // sdp:returnCode
        while (list.item(i) != null) {
            element = (Element) list.item(i);
            //System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            //System.out.println(element.getNodeName());
            if (element.hasChildNodes()) {
                contents = element.getFirstChild().getNodeValue();
                //System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55");
                //System.out.println(element.getNodeName());
                //System.out.println(element.getFirstChild().getNodeName());
                if (element.getNodeName().equals("n1:Resource_Unique_Id")) {
                    if (element.getNextSibling().getFirstChild().getNodeValue().equals(("06"))) {
                        //System.out.println("%%%%%%%%%%%%%%%%% FINDFIND!!! %%%%%%%%%%%%%%%%%%%%%%%%%%%55");
                        strIMEI = element.getFirstChild().getNodeValue();

                        //System.out.println("%%%%%%%%%%%%%%%%% FINDFIND!!!  " + strIMEI + "%%%%%%%%%%%%%%%%%%%%%%%%%%%55");
                    }
                    //resultStr = element.getFirstChild().getNodeName();
                }
                if (element.getNodeName().equals("n1:Resource_Model_Name")) {
                    Model_Name = element.getFirstChild().getNodeValue();
                }
                if (element.getNodeName().equals("sdp:returnCode")) {
                    return_cd = element.getFirstChild().getNodeValue();
                }
                //n1:Resource_Model_Name
                System.out.println(contents);
            }
            i++;
        }
        connection.disconnect();

    } catch (Exception e) {
        e.printStackTrace();
    }

    resVO.setModem_model_nm(Model_Name);
    resVO.setImei(strIMEI);
    resVO.setReturn_cd(return_cd);
    return resVO;
}