Search in sources :

Example 36 with Property

use of org.jvnet.hk2.config.types.Property in project Payara by payara.

the class DefaultConfigUpgrade method createProviderConfigProperty.

private void createProviderConfigProperty(ProviderConfig pc) throws PropertyVetoException {
    while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("provider-config"))) {
        try {
            if (parser.next() == START_ELEMENT) {
                if (parser.getLocalName().equals("property") && pc != null) {
                    Property p = pc.createChild(Property.class);
                    pc.getProperty().add(p);
                    createProperty(p);
                }
            }
        } catch (TransactionFailure ex) {
            logger.log(Level.SEVERE, createProviderConfigPropertyFailed, ex);
        } catch (XMLStreamException ex) {
            logger.log(Level.SEVERE, problemParsingProviderConfigProp, ex);
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) Property(org.jvnet.hk2.config.types.Property)

Example 37 with Property

use of org.jvnet.hk2.config.types.Property in project Payara by payara.

the class DefaultConfigUpgrade method createAdminServiceProperty.

/*  <property value="${com.sun.aas.installRoot}/lib/install/applications/admingui.war"
     * name="adminConsoleDownloadLocation"/>
     */
private void createAdminServiceProperty(AdminService as) throws PropertyVetoException {
    while (true) {
        try {
            if (parser.next() == START_ELEMENT) {
                if (parser.getLocalName().equals("property")) {
                    Property p = as.createChild(Property.class);
                    as.getProperty().add(p);
                    createProperty(p);
                    break;
                }
            }
        } catch (TransactionFailure ex) {
            logger.log(Level.SEVERE, failedToCreateAdminService, ex);
        } catch (XMLStreamException ex) {
            logger.log(Level.SEVERE, problemParsingAdminService, ex);
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) Property(org.jvnet.hk2.config.types.Property)

Example 38 with Property

use of org.jvnet.hk2.config.types.Property in project Payara by payara.

the class GrizzlyConfigSchemaMigrator method promoteVirtualServerProperties.

private void promoteVirtualServerProperties(HttpService service) throws TransactionFailure {
    for (VirtualServer virtualServer : service.getVirtualServer()) {
        ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {

            @Override
            public Object run(VirtualServer param) throws PropertyVetoException {
                if (param.getHttpListeners() != null && !"".equals(param.getHttpListeners())) {
                    param.setNetworkListeners(param.getHttpListeners());
                }
                param.setHttpListeners(null);
                final List<Property> propertyList = new ArrayList<Property>(param.getProperty());
                final Iterator<Property> it = propertyList.iterator();
                while (it.hasNext()) {
                    final Property property = it.next();
                    if ("docroot".equals(property.getName())) {
                        param.setDocroot(property.getValue());
                        it.remove();
                    } else if ("accesslog".equals(property.getName())) {
                        param.setAccessLog(property.getValue());
                        it.remove();
                    } else if ("sso-enabled".equals(property.getName())) {
                        param.setSsoEnabled(property.getValue());
                        it.remove();
                    }
                }
                param.getProperty().clear();
                param.getProperty().addAll(propertyList);
                return null;
            }
        }, virtualServer);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 39 with Property

use of org.jvnet.hk2.config.types.Property in project Payara by payara.

the class TargetBasedResolver method getTarget.

private <T extends ConfigBeanProxy> T getTarget(Class<? extends ConfigBeanProxy> targetType, Class<T> type) throws ClassNotFoundException {
    // when using the target based parameter, we look first for a configuration of that name,
    // then we look for a cluster of that name and finally we look for a subelement of the right type
    final String name = getName();
    ConfigBeanProxy config = habitat.getService(targetType, target);
    if (config != null) {
        try {
            return type.cast(config);
        } catch (ClassCastException e) {
        // ok we need to do more work to find which object is really requested.
        }
        Dom parentDom = Dom.unwrap(config);
        String elementName = GenericCrudCommand.elementName(parentDom.document, targetType, type);
        if (elementName == null) {
            return null;
        }
        ConfigModel.Property property = parentDom.model.getElement(elementName);
        if (property.isCollection()) {
            Collection<Dom> collection;
            synchronized (parentDom) {
                collection = parentDom.nodeElements(elementName);
            }
            if (collection == null) {
                return null;
            }
            for (Dom child : collection) {
                if (name.equals(child.attribute("ref"))) {
                    return type.cast(child.<ConfigBeanProxy>createProxy());
                }
            }
        }
    }
    return null;
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Dom(org.jvnet.hk2.config.Dom) ConfigModel(org.jvnet.hk2.config.ConfigModel)

Example 40 with Property

use of org.jvnet.hk2.config.types.Property in project Payara by payara.

the class DuplicateKeyedElementTest method identicalKeyTest.

@Test(expected = TransactionFailure.class)
public void identicalKeyTest() throws TransactionFailure {
    HttpService httpService = getHabitat().getService(HttpService.class);
    assertNotNull(httpService);
    // let's find a acceptable target.
    VirtualServer target = null;
    for (VirtualServer vs : httpService.getVirtualServer()) {
        if (!vs.getProperty().isEmpty()) {
            target = vs;
            break;
        }
    }
    assertNotNull(target);
    Property newProp = (Property) ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {

        public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
            // first one is fine...
            Property firstProp = param.createChild(Property.class);
            firstProp.setName("foo");
            firstProp.setValue("bar");
            param.getProperty().add(firstProp);
            // this should fail...
            Property secondProp = param.createChild(Property.class);
            secondProp.setName("foo");
            secondProp.setValue("bar");
            param.getProperty().add(secondProp);
            return secondProp;
        }
    }, target);
    // if we arrive here, this is an error, we succeeded adding a property with
    // the same key name.
    assertTrue(false);
}
Also used : SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) HttpService(com.sun.enterprise.config.serverbeans.HttpService) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Test(org.junit.Test)

Aggregations

Property (org.jvnet.hk2.config.types.Property)149 PropertyVetoException (java.beans.PropertyVetoException)30 HashMap (java.util.HashMap)27 Properties (java.util.Properties)22 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)22 ArrayList (java.util.ArrayList)18 ActionReport (org.glassfish.api.ActionReport)17 Map (java.util.Map)15 File (java.io.File)13 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)12 Config (com.sun.enterprise.config.serverbeans.Config)11 List (java.util.List)11 AuthRealm (com.sun.enterprise.config.serverbeans.AuthRealm)10 HttpService (com.sun.enterprise.config.serverbeans.HttpService)9 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)9 Server (com.sun.enterprise.config.serverbeans.Server)8 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)8 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)8 Application (com.sun.enterprise.config.serverbeans.Application)7 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)7