Examples of CustomizationTokensProvider


Examples of com.sun.enterprise.config.modularity.customization.CustomizationTokensProvider

* @author Masoud Kalali
*/
public class CustomizationTokensProviderFactory {

    public static CustomizationTokensProvider createCustomizationTokensProvider() {
        return new CustomizationTokensProvider();
    }
View Full Code Here

Examples of com.sun.enterprise.config.modularity.customization.CustomizationTokensProvider

     *   if no custom token found.
     * @throws DomainException If error occurred in retrieving the
     *   custom tokens.
     */
    public Map<String, String> getSubstitutableTokens() throws DomainException {
        CustomizationTokensProvider provider = CustomizationTokensProviderFactory.createCustomizationTokensProvider();
        Map<String, String> generatedTokens = new HashMap<String, String>();
        String lineSeparator = System.getProperty("line.separator");
        int noOfTokens = 0;
        try {
            List<ConfigCustomizationToken> customTokens = provider.getPresentConfigCustomizationTokens();
            if (!customTokens.isEmpty()) {
                StringBuffer generatedSysTags = new StringBuffer();

                // Check presence of token place-holder
                Set<Integer> usedPorts = new HashSet<Integer>();
                Properties domainProps = _domainConfig.getDomainProperties();
                String portBase = (String)_domainConfig.get(DomainConfig.K_PORTBASE);

                Map<String, String> filePaths = new HashMap<String, String>(3, 1);
                filePaths.put(SystemPropertyConstants.INSTALL_ROOT_PROPERTY, System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
                filePaths.put(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY, System.getProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY));
                filePaths.put(SystemPropertyConstants.JAVA_ROOT_PROPERTY, System.getProperty(SystemPropertyConstants.JAVA_ROOT_PROPERTY));
                noOfTokens = customTokens.size();
                for (ConfigCustomizationToken token : customTokens) {
                    String name = token.getName();
                    // Check for valid custom token parameters.
                    if (isNullOrEmpty(name) || isNullOrEmpty(token.getValue()) || isNullOrEmpty(token.getDescription())) {
                        throw new IllegalArgumentException(_strings.get("invalidTokenParameters", name, token.getValue(), token.getDescription()));
                    }
                    switch (token.getCustomizationType()) {
                        case PORT :
                            Integer port = null;
                            if (domainProps.containsKey(name)) {
                                port = Integer.valueOf(domainProps.getProperty(token.getName()));
                                if (!NetUtils.isPortFree(port)) {
                                    throw new DomainException(_strings.get("unavailablePort", port));
                                }
                            } else {
                                if (portBase != null && token.getTokenTypeDetails() instanceof PortTypeDetails) {
                                    PortTypeDetails portTypeDetails = (PortTypeDetails)token.getTokenTypeDetails();
                                    port = Integer.valueOf(domainProps.getProperty(token.getName())) + Integer.valueOf(portTypeDetails.getBaseOffset());
                                    if (!generatedTokens.containsKey(PORTBASE_PLACE_HOLDER)) {
                                        // Adding a token to persist port base value as a system tag
                                        generatedTokens.put(PORTBASE_PLACE_HOLDER, SystemPropertyTagBuilder.buildSystemTag(
                                                PORTBASE_PLACE_HOLDER, portBase));
                                    }
                                } else {
                                    port = Integer.valueOf(token.getValue());
                                }
                                // Find next available unused port by incrementing the port value by 1
                                while (!NetUtils.isPortFree(port) && !usedPorts.contains(port++));
                            }
                            usedPorts.add(port);
                            generatedSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token, port.toString()));
                            break;
                        case FILE:
                            String path = token.getValue();
                            for (Map.Entry<String, String> entry : filePaths.entrySet()) {
                                if (path.contains(entry.getKey())) {
                                    path = path.replace(entry.getKey(), entry.getValue());
                                    break;
                                }
                            }
                            if (token.getTokenTypeDetails() instanceof FileTypeDetails) {
                                FileTypeDetails details = (FileTypeDetails) token.getTokenTypeDetails();
                                File file = new File(path);
                                switch (details.getExistCondition()) {
                                    case MUST_EXIST:
                                        if (!file.exists()) {
                                            throw new DomainException(_strings.get("missingFile", file.getAbsolutePath()));
                                        }
                                        break;
                                    case MUST_NOT_EXIST:
                                        if (file.exists()) {
                                            throw new DomainException(_strings.get("filePresenceNotDesired", file.getAbsolutePath()));
                                        }
                                        break;
                                    case NO_OP:
                                        break;
                                }
                            }
                            generatedSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token, path));
                            break;
                        case STRING:
                            generatedSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token));
                            break;
                    }
                    if (--noOfTokens > 0) {
                        generatedSysTags.append(lineSeparator);
                    }
                }
                String tags = generatedSysTags.toString();
                if (!isNullOrEmpty(tags)) {
                    generatedTokens.put(CUSTOM_TOKEN_PLACE_HOLDER, tags);
                }
            }
            List<ConfigCustomizationToken> defaultTokens = provider.getPresentDefaultConfigCustomizationTokens();
            if (!defaultTokens.isEmpty()) {
                StringBuffer defaultSysTags = new StringBuffer();
                noOfTokens = defaultTokens.size();
                for (ConfigCustomizationToken token : defaultTokens) {
                    defaultSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token));
View Full Code Here

Examples of com.sun.enterprise.config.modularity.customization.CustomizationTokensProvider

     *   if no custom token found.
     * @throws DomainException If error occurred in retrieving the
     *   custom tokens.
     */
    public Map<String, String> getSubstitutableTokens() throws DomainException {
        CustomizationTokensProvider provider = CustomizationTokensProviderFactory.createCustomizationTokensProvider();
        Map<String, String> generatedTokens = new HashMap<String, String>();
        try {
            List<ConfigCustomizationToken> customTokens = provider.getPresentConfigCustomizationTokens();
            if (!customTokens.isEmpty()) {
                StringBuffer newlyCreatedSysProps = new StringBuffer();
                File domainXMLFile = new File(_configDirLocation, DomainConstants.DOMAIN_XML_FILE);
                FileReader reader = null;
                String loadedDomainXML = null;
View Full Code Here

Examples of com.sun.enterprise.config.modularity.customization.CustomizationTokensProvider

* @author Masoud Kalali
*/
public class CustomizationTokensProviderFactory {

    public static CustomizationTokensProvider createCustomizationTokensProvider() {
        return new CustomizationTokensProvider();
    }
View Full Code Here

Examples of com.sun.enterprise.config.modularity.customization.CustomizationTokensProvider

     *   if no custom token found.
     * @throws DomainException If error occurred in retrieving the
     *   custom tokens.
     */
    public Map<String, String> getSubstitutableTokens() throws DomainException {
        CustomizationTokensProvider provider = CustomizationTokensProviderFactory.createCustomizationTokensProvider();
        Map<String, String> generatedTokens = new HashMap<String, String>();
        String lineSeparator = System.getProperty("line.separator");
        int noOfTokens = 0;
        try {
            List<ConfigCustomizationToken> customTokens = provider.getPresentConfigCustomizationTokens();
            if (!customTokens.isEmpty()) {
                StringBuffer generatedSysTags = new StringBuffer();

                // Check presence of token place-holder
                Set<Integer> usedPorts = new HashSet<Integer>();
                Properties domainProps = _domainConfig.getDomainProperties();
                String portBase = (String)_domainConfig.get(DomainConfig.K_PORTBASE);

                Map<String, String> filePaths = new HashMap<String, String>(3, 1);
                filePaths.put(SystemPropertyConstants.INSTALL_ROOT_PROPERTY, System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
                filePaths.put(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY, System.getProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY));
                filePaths.put(SystemPropertyConstants.JAVA_ROOT_PROPERTY, System.getProperty(SystemPropertyConstants.JAVA_ROOT_PROPERTY));
                noOfTokens = customTokens.size();
                for (ConfigCustomizationToken token : customTokens) {
                    String name = token.getName();
                    // Check for valid custom token parameters.
                    if (isNullOrEmpty(name) || isNullOrEmpty(token.getValue()) || isNullOrEmpty(token.getDescription())) {
                        throw new IllegalArgumentException(_strings.get("invalidTokenParameters", name, token.getValue(), token.getDescription()));
                    }
                    switch (token.getCustomizationType()) {
                        case PORT :
                            Integer port = null;
                            if (domainProps.containsKey(name)) {
                                port = Integer.valueOf(domainProps.getProperty(token.getName()));
                                if (!NetUtils.isPortFree(port)) {
                                    throw new DomainException(_strings.get("unavailablePort", port));
                                }
                            } else {
                                if (portBase != null && token.getTokenTypeDetails() instanceof PortTypeDetails) {
                                    PortTypeDetails portTypeDetails = (PortTypeDetails)token.getTokenTypeDetails();
                                    port = Integer.valueOf(portBase) + Integer.valueOf(portTypeDetails.getBaseOffset());
                                    if (!generatedTokens.containsKey(PORTBASE_PLACE_HOLDER)) {
                                        // Adding a token to persist port base value as a system tag
                                        generatedTokens.put(PORTBASE_PLACE_HOLDER, SystemPropertyTagBuilder.buildSystemTag(
                                                PORTBASE_PLACE_HOLDER, portBase));
                                    }
                                } else {
                                    port = Integer.valueOf(token.getValue());
                                }
                                // Find next available unused port by incrementing the port value by 1
                                while (!NetUtils.isPortFree(port) && !usedPorts.contains(port++));
                            }
                            usedPorts.add(port);
                            generatedSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token, port.toString()));
                            break;
                        case FILE:
                            String path = token.getValue();
                            for (Map.Entry<String, String> entry : filePaths.entrySet()) {
                                if (path.contains(entry.getKey())) {
                                    path = path.replace(entry.getKey(), entry.getValue());
                                    break;
                                }
                            }
                            if (token.getTokenTypeDetails() instanceof FileTypeDetails) {
                                FileTypeDetails details = (FileTypeDetails) token.getTokenTypeDetails();
                                File file = new File(path);
                                switch (details.getExistCondition()) {
                                    case MUST_EXIST:
                                        if (!file.exists()) {
                                            throw new DomainException(_strings.get("missingFile", file.getAbsolutePath()));
                                        }
                                        break;
                                    case MUST_NOT_EXIST:
                                        if (file.exists()) {
                                            throw new DomainException(_strings.get("filePresenceNotDesired", file.getAbsolutePath()));
                                        }
                                        break;
                                    case NO_OP:
                                        break;
                                }
                            }
                            generatedSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token, path));
                            break;
                        case STRING:
                            generatedSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token));
                            break;
                    }
                    if (--noOfTokens > 0) {
                        generatedSysTags.append(lineSeparator);
                    }
                }
                String tags = generatedSysTags.toString();
                if (!isNullOrEmpty(tags)) {
                    generatedTokens.put(CUSTOM_TOKEN_PLACE_HOLDER, tags);
                }
            }
            List<ConfigCustomizationToken> defaultTokens = provider.getPresentDefaultConfigCustomizationTokens();
            if (!defaultTokens.isEmpty()) {
                StringBuffer defaultSysTags = new StringBuffer();
                noOfTokens = defaultTokens.size();
                for (ConfigCustomizationToken token : defaultTokens) {
                    defaultSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.