Package org.jvnet.hk2.component

Examples of org.jvnet.hk2.component.Habitat


 
  public void generate(PrintWriter writer) throws IOException {
    descriptor.clear();

    InhabitantsParserDescriptorWriter ip = new InhabitantsParserDescriptorWriter();
    InhabitantsFeed feed = InhabitantsFeed.create(new Habitat(), ip);
    feed.populate(ipcGen);

    // flush the last inhabitant to the descriptor
    ip.flush();
   
View Full Code Here


     public static void initialize(Client client){
        if (client == null){
            client = JERSEY_CLIENT;
        }
        try{
            Habitat habitat = SecurityServicesUtil.getInstance().getHabitat();
            SecureAdmin secureAdmin = habitat.getComponent(SecureAdmin.class);
            HTTPSProperties httpsProperties = new HTTPSProperties(new BasicHostnameVerifier(),
                habitat.getComponent(SSLUtils.class).getAdminSSLContext(SecureAdmin.Util.DASAlias(secureAdmin), null ));
            client.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, httpsProperties);
            client.addFilter(new CsrfProtectionFilter());
        }catch(Exception ex){
            GuiUtil.getLogger().warning("RestUtil.initialize() failed");
            if (GuiUtil.getLogger().isLoggable(Level.FINE)){
View Full Code Here

        return javaGlobalPrefix.toString();
    }

    protected EJBContextImpl createEjbInstanceAndContext() throws Exception {

  Habitat h = ejbContainerUtilImpl.getDefaultHabitat();

        JCDIService jcdiService = h.getByContract(JCDIService.class);

        EjbBundleDescriptor ejbBundle = ejbDescriptor.getEjbBundleDescriptor();

  Object instance = null;
  JCDIService.JCDIInjectionContext jcdiCtx = null;
View Full Code Here

  return ejbClass.newInstance();
    }

    protected void injectEjbInstance(EJBContextImpl context) throws Exception {
       
        Habitat h = ejbContainerUtilImpl.getDefaultHabitat();

        JCDIService jcdiService = h.getByContract(JCDIService.class);

        EjbBundleDescriptor ejbBundle = ejbDescriptor.getEjbBundleDescriptor();

        Object[] interceptorInstances = null;
View Full Code Here

                Set<String> attributeNames = configBean.model.getAttributeNames();
                for (String attributeName : attributeNames) {
                    String methodName = getAttributeMethodName(attributeName);
                    try {
                        Method method = configBeanProxy.getMethod(methodName);
                        Attribute attribute = method.getAnnotation(Attribute.class);
                        if (attribute != null) {
                            ParameterMetaData parameterMetaData =
                                getParameterMetaData(attribute);

                            if (pamameterType == Constants.QUERY_PARAMETER) {
View Full Code Here

            Resource res = (Resource) configBean;
            return res.getIdentity();
        }
        Method[] methods = configBeanType.getMethods();
        for (Method method : methods) {
            Attribute attributeAnnotation = method.getAnnotation(Attribute.class);
            if ((attributeAnnotation != null) && attributeAnnotation.key()) {
                return (String) method.invoke(configBean);
            }
        }
        return null;
    }
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) {
                    LogHelper.log(LOG, Level.INFO, cannotGetParentConfigBean, e, childElement);
                }
            }
            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;
            if (curLevel.contains("[")) {
                expression = curLevel.substring(curLevel.lastIndexOf("[") + 1, curLevel.length() - 1);
            } else {
                expression = curLevel;
            }

            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

    public <T extends ConfigBeanProxy> T setConfigBean(T finalConfigBean, ConfigBeanDefaultValue configBeanDefaultValue, ConfigBeanProxy parent) {
        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() || !stackPositionHigher(finalConfigBean, configBeanInstance)) {
                    if (configBeanInstance != null) return (T) configBeanInstance;
                }
                if (configBeanInstance != null) {
                    extensions.remove(configBeanInstance);
                }
            }

        } catch (InvocationTargetException e) {
            LOG.log(Level.INFO, cannotSetConfigBean, e);
        } catch (IllegalAccessException e) {
            LOG.log(Level.INFO, cannotSetConfigBean, 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) {
                LogHelper.log(LOG, Level.INFO, cannotSetConfigBeanFor, e, finalConfigBean.getClass().getName());
            }
            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

        //go up in the parents tree till meet someone ImplementingSystemProperty
        //then that is the freaking parent, get it and set the SystemProperty :D
        if (parent instanceof SystemPropertyBag) {
            addSystemPropertyForToken(configBeanDefaultValue.getCustomizationTokens(), (SystemPropertyBag) parent);
        } else {
            ConfigBeanProxy curParent = finalConfigBean;
            while (!(curParent instanceof SystemPropertyBag)) {
                curParent = curParent.getParent();
            }
            if (configBeanDefaultValue.getCustomizationTokens().size() != 0) {
                final boolean oldIP = isIgnorePersisting();
                try {
                    setIgnorePersisting(true);
View Full Code Here

                    // by default, people get the translated view.
                    return new GlassFishConfigBean(serviceLocator, this, dom, configModel, xmlStreamReader);
                }
            };

            ConfigBeanProxy parent = getOwningObject(defaultValue.getLocation());
            ConfigurationPopulator populator = new ConfigurationPopulator(defaultValue.getXmlConfiguration(), doc, parent);
            populator.run(configParser);
            ConfigBeanProxy configBean = doc.getRoot().createProxy(configBeanClass);
            Collection col = (Collection) m.invoke(parent);
            return (T) getConfigBeanFromCollection(col, configBean, configBeanClass);

        }
        return null;
View Full Code Here

TOP

Related Classes of org.jvnet.hk2.component.Habitat

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.