Search in sources :

Example 36 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class HK2DomConfigTypesUtilities method enableHK2DomConfigurationConfigTypes.

/**
 * This method enables the HK2 Dom based XML configuration parsing for
 * systems that do not use HK2 metadata files or use a non-default
 * name for HK2 metadata files, along with support for the types
 * provided in this module.  This method is idempotent, so that
 * if the services already are available in the locator they will
 * not get added again
 *
 * @param locator The non-null locator to add the hk2 dom based
 * configuration services to
 * @param loader The loader to use to classload the services added
 */
public static void enableHK2DomConfigurationConfigTypes(ServiceLocator locator, HK2Loader loader) {
    if (locator.getBestDescriptor(BuilderHelper.createContractFilter(PROPERTY_GENERATED_INJECTOR_CLASS)) != null)
        return;
    HK2DomConfigUtilities.enableHK2DomConfiguration(locator, loader);
    LinkedList<String> namedList = new LinkedList<String>();
    namedList.add(REQUIRED);
    namedList.add(STRING_DATATYPE);
    namedList.add(LEAF);
    LinkedList<String> valueList = new LinkedList<String>();
    valueList.add(REQUIRED);
    valueList.add(STRING_DATATYPE);
    valueList.add(LEAF);
    LinkedList<String> keyedAsList = new LinkedList<String>();
    keyedAsList.add(PROPERTY_CLASS);
    LinkedList<String> targetList = new LinkedList<String>();
    targetList.add(PROPERTY_CLASS);
    LinkedList<String> descriptionList = new LinkedList<String>();
    descriptionList.add(OPTIONAL);
    descriptionList.add(STRING_DATATYPE);
    descriptionList.add(LEAF);
    DescriptorImpl injectorDescriptor = BuilderHelper.link(PROPERTY_GENERATED_INJECTOR_CLASS).to(CONFIG_INJECTOR_CLASS).in(Singleton.class.getName()).named(NAME).qualifiedBy(INJECTION_TARGET_QUALIFIER).has(NAME_FIELD, namedList).has(VALUE_FIELD, valueList).has(KEYED_AS, keyedAsList).has(TARGET, targetList).has(DESCRIPTION_FIELD, descriptionList).has(KEY, NAME_FIELD).build();
    // A strangeness of using name from @Service
    injectorDescriptor.removeQualifier(Named.class.getName());
    if (loader != null) {
        injectorDescriptor.setLoader(loader);
    }
    ServiceLocatorUtilities.addOneDescriptor(locator, injectorDescriptor);
}
Also used : Named(javax.inject.Named) DescriptorImpl(org.glassfish.hk2.utilities.DescriptorImpl) LinkedList(java.util.LinkedList)

Example 37 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class HK2DomConfigUtilities method enableHK2DomConfiguration.

/**
 * This method enables HK2 Dom based XML configuration parsing for
 * systems that do not use HK2 metadata files or use a non-default
 * name for HK2 metadata files.  This method is idempotent, so that
 * if the services already are available in the locator they will
 * not get added again
 *
 * @param locator The non-null locator to add the hk2 dom based
 * configuration services to
 */
public static void enableHK2DomConfiguration(ServiceLocator locator, HK2Loader loader) {
    DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
    DynamicConfiguration config = dcs.createDynamicConfiguration();
    boolean dirty = false;
    boolean operationDirty;
    operationDirty = addIfNotThere(locator, config, getConfigSupport(), loader);
    dirty = dirty || operationDirty;
    operationDirty = addIfNotThere(locator, config, getConfigurationPopulator(), loader);
    dirty = dirty || operationDirty;
    operationDirty = addIfNotThere(locator, config, getTransactions(), loader);
    dirty = dirty || operationDirty;
    operationDirty = addIfNotThere(locator, config, getConfigInstanceListener(), loader);
    dirty = dirty || operationDirty;
    if (dirty) {
        config.commit();
    }
}
Also used : DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration)

Example 38 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class TemplateListOfResource method getPostCommand.

/**
 * allows for remote files to be put in a tmp area and we pass the
 * local location of this file to the corresponding command instead of the content of the file
 * * Yu need to add  enctype="multipart/form-data" in the form
 * for ex:  <form action="http://localhost:4848/management/domain/applications/application" method="post" enctype="multipart/form-data">
 * then any param of type="file" will be uploaded, stored locally and the param will use the local location
 * on the server side (ie. just the path)
 */
public String getPostCommand() {
    ConfigModel.Property p = parent.model.getElement(tagName);
    if (p == null) {
        // "*"
        ConfigModel.Property childElement = parent.model.getElement("*");
        if (childElement != null) {
            ConfigModel.Node node = (ConfigModel.Node) childElement;
            ConfigModel childModel = node.getModel();
            List<ConfigModel> subChildConfigModels = ResourceUtil.getRealChildConfigModels(childModel, parent.document);
            for (ConfigModel subChildConfigModel : subChildConfigModels) {
                if (subChildConfigModel.getTagName().equals(tagName)) {
                    return ResourceUtil.getCommand(RestRedirect.OpType.POST, subChildConfigModel);
                }
            }
        }
    } else {
        ConfigModel.Node n = (ConfigModel.Node) p;
        String command = ResourceUtil.getCommand(RestRedirect.OpType.POST, n.getModel());
        if (command != null) {
            return command;
        }
        // last  possible case...the @Create annotation on a parent method
        Class<? extends ConfigBeanProxy> cbp = null;
        try {
            cbp = (Class<? extends ConfigBeanProxy>) parent.model.classLoaderHolder.loadClass(parent.model.targetTypeName);
        } catch (MultiException e) {
            // 
            return null;
        }
        Create create = null;
        for (Method m : cbp.getMethods()) {
            ConfigModel.Property pp = parent.model.toProperty(m);
            if ((pp != null) && (pp.xmlName.equals(tagName)) && (m.isAnnotationPresent(Create.class))) {
                create = m.getAnnotation(Create.class);
                break;
            }
        }
        if (create != null) {
            return create.value();
        }
    }
    return null;
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel) Create(org.glassfish.config.support.Create) Method(java.lang.reflect.Method) MultiException(org.glassfish.hk2.api.MultiException)

Example 39 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class TemplateRestResource method doCreateOrUpdate.

/**
 * This method performs the creation or updating of an entity, regardless of the
 * request's mime type.  If an error occurs, a <code>WebApplicationException</code>
 * is thrown, so if the method returns, the create/update was successful.
 * @param data
 * @return
 */
protected RestActionReporter doCreateOrUpdate(HashMap<String, String> data) {
    if (data == null) {
        data = new HashMap<String, String>();
    }
    try {
        // data.remove("submit");
        removeAttributesToBeSkipped(data);
        if (data.containsKey("error")) {
            throw new WebApplicationException(Response.status(400).entity(ResourceUtil.getActionReportResult(ActionReport.ExitCode.FAILURE, localStrings.getLocalString("rest.request.parsing.error", "Unable to parse the input entity. Please check the syntax."), requestHeaders, uriInfo)).build());
        }
        ResourceUtil.purgeEmptyEntries(data);
        // client POST request for delete operation to DELETE method.
        if ("__deleteoperation".equals(data.get("operation"))) {
            data.remove("operation");
            delete(data);
            return new RestActionReporter();
        }
        // just update it.
        data = ResourceUtil.translateCamelCasedNamesToXMLNames(data);
        RestActionReporter ar = Util.applyChanges(data, uriInfo, getSubject());
        if (ar.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
            // i18n
            throwError(Status.BAD_REQUEST, "Could not apply changes:  " + ar.getMessage());
        }
        return ar;
    } catch (WebApplicationException wae) {
        throw wae;
    } catch (Exception ex) {
        throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) MultiException(org.glassfish.hk2.api.MultiException) WebApplicationException(javax.ws.rs.WebApplicationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 40 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class TemplateRestResource method getDeleteCommand.

protected String getDeleteCommand() {
    if (entity == null) {
        return null;
    }
    String result = ResourceUtil.getCommand(RestRedirect.OpType.DELETE, getEntity().model);
    if ((result == null) && (entity.parent() != null)) {
        // trying @Delete annotation that as a generic CRUD delete command, possibly...
        Class<? extends ConfigBeanProxy> cbp = null;
        try {
            cbp = (Class<? extends ConfigBeanProxy>) entity.parent().model.classLoaderHolder.loadClass(entity.parent().model.targetTypeName);
        } catch (MultiException e) {
            // 
            return null;
        }
        Delete del = null;
        for (Method m : cbp.getMethods()) {
            ConfigModel.Property pp = entity.parent().model.toProperty(m);
            if ((pp != null) && (pp.xmlName.equals(tagName)) && m.isAnnotationPresent(Delete.class)) {
                del = m.getAnnotation(Delete.class);
                break;
            }
        }
        if (del != null) {
            return del.value();
        }
    }
    return result;
}
Also used : Delete(org.glassfish.config.support.Delete) ConfigModel(org.jvnet.hk2.config.ConfigModel) Method(java.lang.reflect.Method) MultiException(org.glassfish.hk2.api.MultiException)

Aggregations

MultiException (org.glassfish.hk2.api.MultiException)18 Method (java.lang.reflect.Method)16 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)12 GeneratorAdapter (org.glassfish.hk2.external.org.objectweb.asm.commons.GeneratorAdapter)8 Method (org.glassfish.hk2.external.org.objectweb.asm.commons.Method)8 PrivilegedActionException (java.security.PrivilegedActionException)7 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)6 URISyntaxException (java.net.URISyntaxException)6 ExecutionException (java.util.concurrent.ExecutionException)6 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)6 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)6 File (java.io.File)5 HashMap (java.util.HashMap)5 ConfigModel (org.jvnet.hk2.config.ConfigModel)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Attribute (org.jvnet.hk2.config.Attribute)4 PropertyVetoException (java.beans.PropertyVetoException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 HashSet (java.util.HashSet)3