Search in sources :

Example 6 with ConfigBeanDefaultValue

use of com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue in project Payara by payara.

the class CreateModuleConfigCommand method getDefaultConfigFor.

private String getDefaultConfigFor(Class configBeanType) throws Exception {
    if (!configModularityUtils.hasCustomConfig(configBeanType)) {
        return configModularityUtils.serializeConfigBeanByType(configBeanType);
    } else {
        List<ConfigBeanDefaultValue> defaults = configModularityUtils.getDefaultConfigurations(configBeanType, configModularityUtils.getRuntimeTypePrefix(serverenv.getStartupContext()));
        StringBuilder builder = new StringBuilder();
        for (ConfigBeanDefaultValue value : defaults) {
            builder.append(localStrings.getLocalString("at.location", "At Location: "));
            builder.append(replaceExpressionsWithValues(value.getLocation()));
            // builder.append(LINE_SEPARATOR);
            String substituted = replacePropertiesWithDefaultValues(value.getCustomizationTokens(), value.getXmlConfiguration());
            builder.append(substituted);
        // builder.append(LINE_SEPARATOR);
        }
        builder.deleteCharAt(builder.length() - 1);
        return builder.toString();
    }
}
Also used : ConfigBeanDefaultValue(com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue)

Example 7 with ConfigBeanDefaultValue

use of com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue in project Payara by payara.

the class ModuleConfigurationLoader method addConfigBeanFor.

protected <U extends ConfigBeanProxy> void addConfigBeanFor(Class<U> extensionType) {
    if (!RankedConfigBeanProxy.class.isAssignableFrom(extensionType) && (getExtension(extensionType, extensionOwner) != null)) {
        return;
    }
    StartupContext context = serviceLocator.getService(StartupContext.class);
    List<ConfigBeanDefaultValue> configBeanDefaultValueList = configModularityUtils.getDefaultConfigurations(extensionType, configModularityUtils.getRuntimeTypePrefix(context));
    configurationParser.parseAndSetConfigBean(configBeanDefaultValueList);
}
Also used : StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) ConfigBeanDefaultValue(com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue)

Example 8 with ConfigBeanDefaultValue

use of com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue in project Payara by payara.

the class ModuleXMLConfigurationFileParser method parseServiceConfiguration.

public List<ConfigBeanDefaultValue> parseServiceConfiguration(InputStream xmlDocumentStream) throws XMLStreamException {
    List<ConfigBeanDefaultValue> configBeans = new ArrayList<ConfigBeanDefaultValue>();
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    inputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
    XMLEventReader eventReader = inputFactory.createXMLEventReader(xmlDocumentStream);
    ConfigBeanDefaultValue configValue = null;
    while (eventReader.hasNext()) {
        XMLEvent event = eventReader.nextEvent();
        if (event.isStartElement()) {
            StartElement startElement = event.asStartElement();
            // If we have a item element we create a new item
            if (startElement.getName().getLocalPart().equalsIgnoreCase(CONFIG_BUNDLE)) {
                configValue = new ConfigBeanDefaultValue();
                Iterator<Attribute> attributes = startElement.getAttributes();
                while (attributes.hasNext()) {
                    Attribute attribute = attributes.next();
                    if (attribute.getName().toString().equals(LOCATION)) {
                        configValue.setLocation(attribute.getValue());
                    } else if (attribute.getName().toString().equals(REPLACE_IF_EXISTS)) {
                        configValue.setReplaceCurrentIfExists(Boolean.parseBoolean(attribute.getValue()));
                    }
                }
                // attributes
                continue;
            }
            if (startElement.getName().getLocalPart().equalsIgnoreCase(CUSTOMIZATION_TOKEN)) {
                ConfigCustomizationToken token;
                String value = null;
                String description = null;
                String name = null;
                String title = null;
                String validationExpression = null;
                ConfigCustomizationToken.CustomizationType type = ConfigCustomizationToken.CustomizationType.STRING;
                TokenTypeDetails tokenTypeDetails = null;
                Iterator<Attribute> attributes = startElement.getAttributes();
                while (attributes.hasNext()) {
                    Attribute attribute = attributes.next();
                    switch(attribute.getName().toString()) {
                        case DEFAULT_VALUE:
                            value = attribute.getValue();
                            break;
                        case DESCRIPTION:
                            description = getLocalizedValue(attribute.getValue());
                            break;
                        case NAME:
                            name = attribute.getValue();
                            break;
                        case TITLE:
                            title = getLocalizedValue(attribute.getValue());
                            break;
                        case VALIDATION_EXPRESSION:
                            validationExpression = getLocalizedValue(attribute.getValue());
                            break;
                        default:
                            break;
                    }
                }
                // attributes
                event = eventReader.nextEvent();
                while (!event.isStartElement() && !event.isEndElement()) {
                    event = eventReader.nextEvent();
                }
                if (event.isStartElement()) {
                    startElement = event.asStartElement();
                    // If we have a item element we create a new item
                    if (startElement.getName().getLocalPart().equalsIgnoreCase(FILE)) {
                        type = ConfigCustomizationToken.CustomizationType.FILE;
                        String tokVal = startElement.getAttributeByName(QName.valueOf(MUST_EXIST)).getValue();
                        FileTypeDetails.FileExistCondition cond = FileTypeDetails.FileExistCondition.NO_OP;
                        if (tokVal.equalsIgnoreCase("true")) {
                            cond = FileTypeDetails.FileExistCondition.MUST_EXIST;
                        } else if (tokVal.equalsIgnoreCase("false")) {
                            cond = FileTypeDetails.FileExistCondition.MUST_NOT_EXIST;
                        }
                        tokenTypeDetails = new FileTypeDetails(cond);
                    } else if (startElement.getName().getLocalPart().equalsIgnoreCase(PORT)) {
                        type = ConfigCustomizationToken.CustomizationType.PORT;
                        tokenTypeDetails = new PortTypeDetails(startElement.getAttributeByName(QName.valueOf(BASE_OFFSET)).getValue());
                    }
                }
                token = new ConfigCustomizationToken(name, title, description, value, validationExpression, tokenTypeDetails, type);
                // TODO check that ConfigValue is not null
                configValue.addCustomizationToken(token);
                continue;
            }
            if (startElement.getName().getLocalPart().equalsIgnoreCase(CONFIGURATION_ELEMENT)) {
                Iterator<Attribute> attributes = startElement.getAttributes();
                while (attributes.hasNext()) {
                    Attribute attribute = attributes.next();
                    if (attribute.getName().toString().equals(CONFIG_BEAN_CLASS_NAME)) {
                        configValue.setConfigBeanClassName(attribute.getValue());
                    }
                }
                // attributes
                event = eventReader.nextEvent();
                if (event.isCharacters()) {
                    String str = event.asCharacters().getData();
                    configValue.setXmlConfiguration(str);
                }
                continue;
            }
        }
        // isStartElement
        if (event.isEndElement()) {
            EndElement endElement = event.asEndElement();
            if (endElement.getName().getLocalPart().equalsIgnoreCase(CONFIG_BUNDLE)) {
                configBeans.add(configValue);
            }
        }
    }
    // eventReader
    return configBeans;
}
Also used : FileTypeDetails(com.sun.enterprise.config.modularity.customization.FileTypeDetails) Attribute(javax.xml.stream.events.Attribute) EndElement(javax.xml.stream.events.EndElement) ArrayList(java.util.ArrayList) PortTypeDetails(com.sun.enterprise.config.modularity.customization.PortTypeDetails) StartElement(javax.xml.stream.events.StartElement) ConfigBeanDefaultValue(com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue) ConfigCustomizationToken(com.sun.enterprise.config.modularity.customization.ConfigCustomizationToken) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) TokenTypeDetails(com.sun.enterprise.config.modularity.customization.TokenTypeDetails) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

ConfigBeanDefaultValue (com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue)8 PropertyVetoException (java.beans.PropertyVetoException)2 ArrayList (java.util.ArrayList)2 CustomConfiguration (com.sun.enterprise.config.modularity.annotation.CustomConfiguration)1 ConfigCustomizationToken (com.sun.enterprise.config.modularity.customization.ConfigCustomizationToken)1 FileTypeDetails (com.sun.enterprise.config.modularity.customization.FileTypeDetails)1 PortTypeDetails (com.sun.enterprise.config.modularity.customization.PortTypeDetails)1 TokenTypeDetails (com.sun.enterprise.config.modularity.customization.TokenTypeDetails)1 ModuleXMLConfigurationFileParser (com.sun.enterprise.config.modularity.parser.ModuleXMLConfigurationFileParser)1 Config (com.sun.enterprise.config.serverbeans.Config)1 StartupContext (com.sun.enterprise.module.bootstrap.StartupContext)1 LocalStringManager (com.sun.enterprise.util.LocalStringManager)1 LocalStringManagerImpl (com.sun.enterprise.util.LocalStringManagerImpl)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1