Search in sources :

Example 21 with Resource

use of org.glassfish.resources.api.Resource in project Payara by payara.

the class ResourcesXMLParser method generateJNDIResource.

/**
 * Generate the JNDI resource
 */
private void generateJNDIResource(Node nextKid, String scope) throws Exception {
    NamedNodeMap attributes = nextKid.getAttributes();
    if (attributes == null)
        return;
    Node jndiNameNode = attributes.getNamedItem(JNDI_NAME);
    String jndiName = getScopedName(jndiNameNode.getNodeValue(), scope);
    Node jndiLookupNode = attributes.getNamedItem(JNDI_LOOKUP);
    String jndiLookup = jndiLookupNode.getNodeValue();
    Node resTypeNode = attributes.getNamedItem(RES_TYPE);
    String resType = resTypeNode.getNodeValue();
    Node factoryClassNode = attributes.getNamedItem(FACTORY_CLASS);
    String factoryClass = factoryClassNode.getNodeValue();
    Node enabledNode = attributes.getNamedItem(ENABLED);
    org.glassfish.resources.api.Resource jndiResource = new Resource(Resource.EXTERNAL_JNDI_RESOURCE);
    jndiResource.setAttribute(JNDI_NAME, jndiName);
    jndiResource.setAttribute(JNDI_LOOKUP, jndiLookup);
    jndiResource.setAttribute(RES_TYPE, resType);
    jndiResource.setAttribute(FACTORY_CLASS, factoryClass);
    if (enabledNode != null) {
        String sEnabled = enabledNode.getNodeValue();
        jndiResource.setAttribute(ENABLED, sEnabled);
    }
    NodeList children = nextKid.getChildNodes();
    generatePropertyElement(jndiResource, children);
    vResources.add(jndiResource);
    resourceMap.put(jndiResource, nextKid);
    // debug strings
    printResourceElements(jndiResource);
}
Also used : Resource(org.glassfish.resources.api.Resource) Resource(org.glassfish.resources.api.Resource)

Example 22 with Resource

use of org.glassfish.resources.api.Resource in project Payara by payara.

the class ResourcesXMLParser method generateJDBCResource.

/**
 * Generate the JDBC resource
 */
private void generateJDBCResource(Node nextKid, String scope) throws Exception {
    NamedNodeMap attributes = nextKid.getAttributes();
    if (attributes == null)
        return;
    Node jndiNameNode = attributes.getNamedItem(JNDI_NAME);
    String jndiName = getScopedName(jndiNameNode.getNodeValue(), scope);
    Node poolNameNode = attributes.getNamedItem(POOL_NAME);
    String poolName = getScopedName(poolNameNode.getNodeValue(), scope);
    Node enabledNode = attributes.getNamedItem(ENABLED);
    Resource jdbcResource = new org.glassfish.resources.api.Resource(org.glassfish.resources.api.Resource.JDBC_RESOURCE);
    jdbcResource.setAttribute(JNDI_NAME, jndiName);
    jdbcResource.setAttribute(POOL_NAME, poolName);
    if (enabledNode != null) {
        String enabledName = enabledNode.getNodeValue();
        jdbcResource.setAttribute(ENABLED, enabledName);
    }
    NodeList children = nextKid.getChildNodes();
    // get description
    if (children != null) {
        for (int ii = 0; ii < children.getLength(); ii++) {
            if (children.item(ii).getNodeName().equals("description")) {
                if (children.item(ii).getFirstChild() != null) {
                    jdbcResource.setDescription(children.item(ii).getFirstChild().getNodeValue());
                }
            }
        }
    }
    vResources.add(jdbcResource);
    resourceMap.put(jdbcResource, nextKid);
    // debug strings
    printResourceElements(jdbcResource);
}
Also used : Resource(org.glassfish.resources.api.Resource)

Example 23 with Resource

use of org.glassfish.resources.api.Resource in project Payara by payara.

the class ResourcesXMLParser method generatePersistenceResource.

private void generatePersistenceResource(Node nextKid) throws Exception {
    NamedNodeMap attributes = nextKid.getAttributes();
    if (attributes == null)
        return;
    Node jndiNameNode = attributes.getNamedItem(JNDI_NAME);
    String jndiName = jndiNameNode.getNodeValue();
    Node factoryClassNode = attributes.getNamedItem(FACTORY_CLASS);
    Node poolNameNode = attributes.getNamedItem(JDBC_RESOURCE_JNDI_NAME);
    Node enabledNode = attributes.getNamedItem(ENABLED);
    Resource persistenceResource = new org.glassfish.resources.api.Resource(org.glassfish.resources.api.Resource.PERSISTENCE_MANAGER_FACTORY_RESOURCE);
    persistenceResource.setAttribute(JNDI_NAME, jndiName);
    if (factoryClassNode != null) {
        String factoryClass = factoryClassNode.getNodeValue();
        persistenceResource.setAttribute(FACTORY_CLASS, factoryClass);
    }
    if (poolNameNode != null) {
        String poolName = poolNameNode.getNodeValue();
        persistenceResource.setAttribute(JDBC_RESOURCE_JNDI_NAME, poolName);
    }
    if (enabledNode != null) {
        String sEnabled = enabledNode.getNodeValue();
        persistenceResource.setAttribute(ENABLED, sEnabled);
    }
    NodeList children = nextKid.getChildNodes();
    generatePropertyElement(persistenceResource, children);
    vResources.add(persistenceResource);
    resourceMap.put(persistenceResource, nextKid);
    // debug strings
    printResourceElements(persistenceResource);
}
Also used : Resource(org.glassfish.resources.api.Resource)

Example 24 with Resource

use of org.glassfish.resources.api.Resource in project Payara by payara.

the class ResourcesDeployer method getResources.

/**
 * Retrieve connector and non-connector resources from the archive.
 *
 * @param archive Archieve from which the resources to be retrieved.
 * @param appName Name of the application
 * @param connectorResources Connector resources will be added to this list.
 * @param nonConnectorResources Non connector resources will be added to this list.
 * @param resourceXmlParsers Resource xml parsers corresponding to both connector and non connector resources will be stored in this.
 */
public void getResources(ReadableArchive archive, String appName, List<org.glassfish.resources.api.Resource> connectorResources, List<org.glassfish.resources.api.Resource> nonConnectorResources, Map<org.glassfish.resources.api.Resource, ResourcesXMLParser> resourceXmlParsers) {
    try {
        if (ResourceUtil.hasResourcesXML(archive, locator)) {
            Map<String, Map<String, List>> appScopedResources = new HashMap<String, Map<String, List>>();
            Map<String, String> fileNames = new HashMap<String, String>();
            // using appName as it is possible that "deploy --name=APPNAME" will
            // be different than the archive name.
            retrieveAllResourcesXMLs(fileNames, archive, appName);
            for (Map.Entry<String, String> entry : fileNames.entrySet()) {
                String moduleName = entry.getKey();
                String fileName = entry.getValue();
                debug("GlassFish Resources XML : " + fileName);
                moduleName = org.glassfish.resourcebase.resources.util.ResourceUtil.getActualModuleNameWithExtension(moduleName);
                String scope;
                if (appName.equals(moduleName)) {
                    scope = JAVA_APP_SCOPE_PREFIX;
                } else {
                    scope = JAVA_MODULE_SCOPE_PREFIX;
                }
                File file = new File(fileName);
                ResourcesXMLParser parser = new ResourcesXMLParser(file, scope);
                validateResourcesXML(file, parser);
                List<org.glassfish.resources.api.Resource> resources = parser.getResourcesList();
                if (nonConnectorResources != null) {
                    nonConnectorResources.addAll(ResourcesXMLParser.getNonConnectorResourcesList(resources, false, true));
                }
                if (connectorResources != null) {
                    connectorResources.addAll(ResourcesXMLParser.getConnectorResourcesList(resources, false, true));
                }
                if (resourceXmlParsers != null) {
                    for (org.glassfish.resources.api.Resource res : resources) {
                        resourceXmlParsers.put(res, parser);
                    }
                }
            }
        }
    } catch (Exception e) {
        // in the event notification infrastructure
        throw new DeploymentException("Failue while processing glassfish-resources.xml(s) in the archive ", e);
    }
}
Also used : ResourcesXMLParser(org.glassfish.resources.admin.cli.ResourcesXMLParser) Resource(com.sun.enterprise.config.serverbeans.Resource) Resource(org.glassfish.resources.api.Resource) ResourceException(javax.resource.ResourceException) IOException(java.io.IOException) DeploymentException(org.glassfish.deployment.common.DeploymentException) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException) Resource(org.glassfish.resources.api.Resource) DeploymentException(org.glassfish.deployment.common.DeploymentException) org.glassfish.resources.api(org.glassfish.resources.api) File(java.io.File)

Aggregations

Resource (org.glassfish.resources.api.Resource)24 Resource (com.sun.enterprise.config.serverbeans.Resource)5 ResourceConflictException (org.glassfish.resourcebase.resources.api.ResourceConflictException)5 org.glassfish.resources.api (org.glassfish.resources.api)4 IOException (java.io.IOException)3 ResourceException (javax.resource.ResourceException)3 DeploymentException (org.glassfish.deployment.common.DeploymentException)3 File (java.io.File)2 ResourcesXMLParser (org.glassfish.resources.admin.cli.ResourcesXMLParser)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)1 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)1 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)1 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)1 ResourceManager (org.glassfish.resources.admin.cli.ResourceManager)1 org.jvnet.hk2.config (org.jvnet.hk2.config)1