Package org.jvnet.hk2.config

Examples of org.jvnet.hk2.config.ConfigBeanProxy


    }
   
    private static String resourceNameFromRestEndpoint(Class<? extends ConfigBeanProxy> c,
            final String path,
            final ServiceLocator locator) {
        ConfigBeanProxy b = locator.getService(c);
        String name = (b != null ? AccessRequired.Util.resourceNameFromConfigBeanProxy(b) : "?");
        if (path != null) {
            name += '/' + path;
        }
        return name;
View Full Code Here


            // returned by HK2.  If that's the case, we can use ConfigModularityUtils.getOwningObject()
            // to find the ConfigBean matching the path requested, which will add the node to
            // the Dom tree. Once that's done, we can return that node and proceed as normal
            String location = buildPath(parent) + "/" + tagName;
            if (location.startsWith("domain/configs")) {
                ConfigBeanProxy cbp = locatorBridge.getRemoteLocator().<ConfigModularityUtils>getService(ConfigModularityUtils.class).getOwningObject(location);
                if (cbp != null) {
                    entity = Dom.unwrap(cbp);
                    childModel = entity.model;
                }
            }
View Full Code Here

                }
                try {
                    Object value = remoteKeyInfo.method.invoke(config);
                    if (value instanceof String) {
                        String key = (String) value;
                        ConfigBeanProxy component = habitat.getService(remoteKeyInfo.annotation.type(), key);
                        if (component == null) {
                            result = false;
                            if (remoteKeyInfo.annotation.message().isEmpty()) {
                                disableGlobalMessage = false;
                            } else {
View Full Code Here

        }
        if (ConfigExtension.class.isAssignableFrom(configBeanType)) {
            if (config == null) {
                config = locator.getService(Config.class, ServerEnvironmentImpl.DEFAULT_INSTANCE_NAME);
            }
            ConfigBeanProxy pr = config.getExtensionByType(configBeanType);
            return pr != null;

        } else if (DomainExtension.class.isAssignableFrom(configBeanType)) {
            ConfigBeanProxy pr = domain.getExtensionByType(configBeanType);
            return pr != null;
        }
        return false;

    }
View Full Code Here

        Class parentClass = configModularityUtils.getOwningClassForLocation(defaultValue.getLocation());
        final Class configBeanClass = configModularityUtils.getClassForFullName(defaultValue.getConfigBeanClassName());
        final Method m = configModularityUtils.findSuitableCollectionGetter(parentClass, configBeanClass);
        if (m != null) {
            try {
                final ConfigBeanProxy parent = configModularityUtils.getOwningObject(defaultValue.getLocation());
                ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() {
                    @Override
                    public Object run(ConfigBeanProxy param) throws PropertyVetoException,
                            TransactionFailure {
                        List col = null;
                        ConfigBeanProxy configBean = null;
                        try {
                            col = (List) m.invoke(param);
                            if (col != null) {
                                configBean = configModularityUtils.getCurrentConfigBeanForDefaultValue(defaultValue);
                            }
View Full Code Here

    private static <T extends ConfigBeanProxy> boolean removeCustomTokens(final ConfigBeanDefaultValue configBeanDefaultValue, T finalConfigBean, ConfigBeanProxy parent) throws TransactionFailure, PropertyVetoException {
        if (parent instanceof SystemPropertyBag) {
            removeSystemPropertyForTokens(configBeanDefaultValue.getCustomizationTokens(), (SystemPropertyBag) parent);
            return true;
        } else {
            ConfigBeanProxy curParent = finalConfigBean;
            while (!(curParent instanceof SystemPropertyBag)) {
                curParent = curParent.getParent();
            }
            if (configBeanDefaultValue.getCustomizationTokens().size() != 0) {
                final SystemPropertyBag bag = (SystemPropertyBag) curParent;
                final List<ConfigCustomizationToken> tokens = configBeanDefaultValue.getCustomizationTokens();
                removeSystemPropertyForTokens(tokens, bag);
View Full Code Here

    }


    private String getDependentConfigElement(ConfigBeanDefaultValue defaultValue)
            throws InvocationTargetException, IllegalAccessException {
        ConfigBeanProxy configBean = configModularityUtils.getCurrentConfigBeanForDefaultValue(defaultValue);
        if (configBean != null) {
            return configModularityUtils.serializeConfigBean(configBean);
        } else {
            return defaultValue.getXmlConfiguration();
        }
View Full Code Here

            }

            // remove the DEFAULT_INSTANCE_NAME entry for an old value
            Object ov = e.getOldValue();
            if (ov instanceof ConfigBeanProxy) {
                ConfigBeanProxy ovbp = (ConfigBeanProxy) ov;
                logger.log(Level.FINE, "removing default instance index for {0}",
                        ConfigSupport.getImpl(ovbp).getProxyType().getName());
                ServiceLocatorUtilities.removeFilter(habitat, BuilderHelper.createNameAndContractFilter(
                        ConfigSupport.getImpl(ovbp).getProxyType().getName(),
                        ServerEnvironment.DEFAULT_INSTANCE_NAME));
            }
           
            // add the DEFAULT_INSTANCE_NAME entry for a new value
            Object nv = e.getNewValue();
            if (nv instanceof ConfigBean) {
                ConfigBean nvb = (ConfigBean) nv;
                ConfigBeanProxy nvbp = nvb.getProxy(nvb.getProxyType());
                logger.log(Level.FINE, "adding default instance index for {0}",
                        nvb.getProxyType().getName());
                ServiceLocatorUtilities.addOneConstant(habitat, nvbp,
                        ServerEnvironment.DEFAULT_INSTANCE_NAME,
                        nvb.getProxyType());
View Full Code Here

            if (tokenizer.countTokens() == 1) {
                return serviceLocator.getService(Domain.class);
            }
            location = location.substring(location.indexOf("/", "domain".length()) + 1);
            tokenizer = new StringTokenizer(location, "/", false);
            ConfigBeanProxy parent = serviceLocator.getService(Domain.class);

            //skipping the domain itself as a token, we know it and took it away.
            String parentElement = "domain";
            String childElement = null;
            while (tokenizer.hasMoreTokens()) {
                try {
                    childElement = tokenizer.nextToken();
                    parent = getOwner(parent, parentElement, childElement);
                    parentElement = childElement;
                } catch (Exception e) {
                    LOG.log(Level.INFO, "cannot get parent config bean for: " + childElement, e);
                }
            }
            return parent;
        } else {
            Class typeToFindGetter = getOwningClassForLocation(location);
            if (typeToFindGetter == null) {
                return null;
            }

            //Check if config object is where the location or it goes deeper in the config layers.
            StringTokenizer tokenizer = new StringTokenizer(location, "/", false);
            //something directly inside the config itself
            if (tokenizer.countTokens() == 3) {
                String expression = location.substring(location.lastIndexOf("[") + 1, location.length() - 1);
                String configName = resolveExpression(expression);
                return serviceLocator.<Domain>getService(Domain.class).getConfigNamed(configName);
            }

            location = location.substring(location.indexOf("/", "domain/configs".length()) + 1);
            tokenizer = new StringTokenizer(location, "/", false);
            String curLevel = tokenizer.nextToken();
            String expression = curLevel.substring(curLevel.lastIndexOf("[") + 1, curLevel.length() - 1);
            String configName = resolveExpression(expression);
            ConfigBeanProxy parent = serviceLocator.<Domain>getService(Domain.class).getConfigNamed(configName);

            String childElement;
            String parentElement = "Config";
            while (tokenizer.hasMoreTokens()) {
                try {
View Full Code Here

        Class owningClassForLocation = getOwningClassForLocation(configBeanDefaultValue.getLocation());
        Class configBeanClass = getClassForFullName(configBeanDefaultValue.getConfigBeanClassName());

        try {
            ConfigBeanProxy configBeanInstance = null;
            if (getNameForConfigBean(finalConfigBean, configBeanClass) == null) {
                List<ConfigBeanProxy> extensions = getExtensions(parent);
                for (ConfigBeanProxy extension : extensions) {
                    try {
                        configBeanInstance = (ConfigBeanProxy) configBeanClass.cast(extension);
                        break;
                    } catch (Exception e) {
                        // ignore, not the right type.
                    }
                }
                if (!configBeanDefaultValue.replaceCurrentIfExists()) {

                    if (configBeanInstance != null) return (T) configBeanInstance;
                } else {
                    if (configBeanInstance != null) {
                        extensions.remove(configBeanInstance);
                    }
                }
            }

        } catch (InvocationTargetException e) {
            LOG.log(Level.INFO, "Cannot set config bean dues to: ", e);
        } catch (IllegalAccessException e) {
            LOG.log(Level.INFO, "Cannot set config bean dues to:", e);
        }


        Method m = getMatchingSetterMethod(owningClassForLocation, configBeanClass);
        if (m != null) {
            try {
                if (configBeanClass.getAnnotation(HasCustomizationTokens.class) != null) {
                    applyCustomTokens(configBeanDefaultValue, finalConfigBean, parent);
                }
                m.invoke(parent, finalConfigBean);
            } catch (Exception e) {
                LOG.log(Level.INFO, "cannot set ConfigBean for: " + finalConfigBean.getClass().getName(), e);
            }
            return finalConfigBean;
        }

        m = findSuitableCollectionGetter(owningClassForLocation, configBeanClass);
        if (m != null) {
            try {
                Collection col = (Collection) m.invoke(parent);
                String name = getNameForConfigBean(finalConfigBean, configBeanClass);
                ConfigBeanProxy itemToRemove = getNamedConfigBeanFromCollection(col, name, configBeanClass);
                if (configBeanDefaultValue.replaceCurrentIfExists()) {
                    try {
                        if (itemToRemove != null) {
                            if (stackPositionHigher(finalConfigBean, itemToRemove)) {
                                col.remove(itemToRemove);
View Full Code Here

TOP

Related Classes of org.jvnet.hk2.config.ConfigBeanProxy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.