Source Code Cross Referenced for ConfigSupportImpl.java in  » 6.0-JDK-Core » j2eeserver » org » netbeans » modules » j2ee » deployment » config » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » j2eeserver » org.netbeans.modules.j2ee.deployment.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001        /*
0002         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003         *
0004         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005         *
0006         * The contents of this file are subject to the terms of either the GNU
0007         * General Public License Version 2 only ("GPL") or the Common
0008         * Development and Distribution License("CDDL") (collectively, the
0009         * "License"). You may not use this file except in compliance with the
0010         * License. You can obtain a copy of the License at
0011         * http://www.netbeans.org/cddl-gplv2.html
0012         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013         * specific language governing permissions and limitations under the
0014         * License.  When distributing the software, include this License Header
0015         * Notice in each file and include the License file at
0016         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017         * particular file as subject to the "Classpath" exception as provided
0018         * by Sun in the GPL Version 2 section of the License file that
0019         * accompanied this code. If applicable, add the following below the
0020         * License Header, with the fields enclosed by brackets [] replaced by
0021         * your own identifying information:
0022         * "Portions Copyrighted [year] [name of copyright owner]"
0023         *
0024         * Contributor(s):
0025         *
0026         * The Original Software is NetBeans. The Initial Developer of the Original
0027         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028         * Microsystems, Inc. All Rights Reserved.
0029         *
0030         * If you wish your version of this file to be governed by only the CDDL
0031         * or only the GPL Version 2, indicate your decision by adding
0032         * "[Contributor] elects to include this software in this distribution
0033         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034         * single choice of license, a recipient has the option to distribute
0035         * your version of this file under either the CDDL, the GPL Version 2 or
0036         * to extend the choice of license to its licensees as provided above.
0037         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038         * Version 2 license, then the option applies only if the new code is
0039         * made subject to such option by the copyright holder.
0040         */
0041
0042        package org.netbeans.modules.j2ee.deployment.config;
0043
0044        import java.io.File;
0045        import java.io.IOException;
0046        import java.io.OutputStream;
0047        import java.util.ArrayList;
0048        import java.util.Collection;
0049        import java.util.Collections;
0050        import java.util.HashMap;
0051        import java.util.Iterator;
0052        import java.util.Map;
0053        import java.util.Set;
0054        import java.util.logging.Level;
0055        import java.util.logging.Logger;
0056        import org.netbeans.modules.j2ee.dd.api.common.ComponentInterface;
0057        import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping;
0058        import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeApplication;
0059        import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
0060        import org.netbeans.modules.j2ee.deployment.impl.Server;
0061        import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
0062        import javax.enterprise.deploy.shared.ModuleType;
0063        import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
0064        import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
0065        import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
0066        import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
0067        import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
0068        import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ContextRootConfiguration;
0069        import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DatasourceConfiguration;
0070        import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DeploymentPlanConfiguration;
0071        import org.netbeans.modules.j2ee.deployment.plugins.spi.config.MappingConfiguration;
0072        import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfiguration;
0073        import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfigurationFactory;
0074        import org.netbeans.modules.j2ee.deployment.plugins.spi.config.EjbResourceConfiguration;
0075        import org.openide.filesystems.FileLock;
0076        import org.openide.filesystems.FileObject;
0077        import org.openide.filesystems.FileUtil;
0078        import org.openide.util.NbBundle;
0079        import org.netbeans.api.project.FileOwnerQuery;
0080        import org.netbeans.api.project.Project;
0081        import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
0082        import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
0083        import org.netbeans.modules.j2ee.deployment.execution.ModuleConfigurationProvider;
0084        import org.netbeans.modules.j2ee.deployment.plugins.spi.config.MessageDestinationConfiguration;
0085        import org.openide.util.Parameters;
0086
0087        /**
0088         * Each J2eeModuleProvider hold a reference to an instance of this config support.
0089         * An instance of ConfigDataObject representing the current target configuration
0090         * and it is cached for to avoid performance penalty of creating new one for every
0091         * access to configuration.
0092         *
0093         * Whenenver target server of the module changes, a new config support is associate
0094         * with the module providing access to the right configuration data object.
0095         *
0096         * @author  nn136682
0097         */
0098        //PENDING: cleanup the usage of fakeserver, refresh. Instead, provide UI feedback for
0099        // case when provider does not associate with any server.
0100        public final class ConfigSupportImpl implements 
0101                J2eeModuleProvider.ConfigSupport, ModuleConfigurationProvider {
0102
0103            private static final File[] EMPTY_FILE_LIST = new File[0];
0104            private static final String GENERIC_EXTENSION = ".dpf"; // NOI18N
0105
0106            private String configurationPrimaryFileName = null;
0107            private Map relativePaths = null;
0108            private Map allRelativePaths = null;
0109
0110            private final J2eeModuleProvider provider;
0111            private final J2eeModule j2eeModule;
0112
0113            private Server server;
0114            private ServerInstance instance;
0115            private ModuleConfiguration moduleConfiguration;
0116
0117            /** Creates a new instance of ConfigSupportImpl */
0118            public ConfigSupportImpl(J2eeModuleProvider provider) {
0119                this .provider = provider;
0120                j2eeModule = provider.getJ2eeModule();
0121                J2eeModuleAccessor.DEFAULT.setJ2eeModuleProvider(j2eeModule,
0122                        provider);
0123                String serverInstanceId = provider.getServerInstanceID();
0124                if (serverInstanceId != null) {
0125                    instance = ServerRegistry.getInstance().getServerInstance(
0126                            serverInstanceId);
0127                    if (instance != null) {
0128                        // project server instance exists
0129                        server = instance.getServer();
0130                    }
0131                }
0132                if (server == null) {
0133                    // project server instance is not set or does not exist
0134                    String serverID = provider.getServerID();
0135                    if (serverID != null) {
0136                        // project server exists
0137                        server = ServerRegistry.getInstance().getServer(
0138                                serverID);
0139                    }
0140                }
0141            }
0142
0143            /**
0144             * This method save configurations in deployment plan in content directory
0145             * and return the fileobject for the plan.  Primary use is for remote deployment
0146             * or standard jsr88 deployement.
0147             */
0148            public File getConfigurationFile() {
0149                try {
0150                    return getDeploymentPlanFileForDistribution();
0151                } catch (Exception ex) {
0152                    Logger.getLogger("global").log(Level.INFO, null, ex);
0153                }
0154                return null;
0155            }
0156
0157            /**
0158             * Return list of server specific configuration files.
0159             */
0160            public static File[] getDeploymentConfigurationFiles(
0161                    J2eeModuleProvider provider, Server server) {
0162                return getDeploymentConfigurationFiles(provider, server, false);
0163            }
0164
0165            public static FileObject[] getConfigurationFiles(
0166                    J2eeModuleProvider jmp) {
0167                Collection servers = ServerRegistry.getInstance().getServers();
0168                ArrayList files = new ArrayList();
0169                for (Iterator i = servers.iterator(); i.hasNext();) {
0170                    Server s = (Server) i.next();
0171                    File[] configs = getDeploymentConfigurationFiles(jmp, s,
0172                            true);
0173                    for (int j = 0; j < configs.length; j++) {
0174                        files.add(FileUtil.toFileObject(configs[j]));
0175                    }
0176                }
0177                return (FileObject[]) files
0178                        .toArray(new FileObject[files.size()]);
0179            }
0180
0181            public String getDeploymentName() {
0182                try {
0183                    FileObject fo = getProvider().getJ2eeModule()
0184                            .getContentDirectory();
0185                    if (fo == null) {
0186                        String configFileName = getPrimaryConfigurationFileName();
0187                        File file = j2eeModule
0188                                .getDeploymentConfigurationFile(configFileName);
0189                        if (file != null) {
0190                            fo = FileUtil.toFileObject(file);
0191                        }
0192                    }
0193                    if (fo == null)
0194                        return null;
0195                    Project owner = FileOwnerQuery.getOwner(fo);
0196                    if (owner != null)
0197                        return owner.getProjectDirectory().getName();
0198
0199                } catch (IOException ioe) {
0200                    Logger.getLogger("global").log(Level.INFO, null, ioe);
0201                }
0202                return null;
0203            }
0204
0205            /** dispose all created deployment configurations */
0206            public void dispose() {
0207                if (server != null) {
0208                    ModuleConfiguration moduleConfig = null;
0209                    synchronized (this ) {
0210                        moduleConfig = moduleConfiguration;
0211                    }
0212                    if (moduleConfig != null) {
0213                        moduleConfig.dispose();
0214                    }
0215                }
0216            }
0217
0218            // J2eeModuleProvider.ConfigSupport ---------------------------------------
0219
0220            public boolean createInitialConfiguration() {
0221                return getModuleConfiguration() != null;
0222            }
0223
0224            public boolean ensureConfigurationReady() {
0225                return getModuleConfiguration() != null;
0226            }
0227
0228            /**
0229             * Get context root (context path)
0230             *
0231             * @return string value, null if not set or not a WAR module
0232             */
0233            public String getWebContextRoot() {
0234                if (!getProvider().getJ2eeModule().getModuleType().equals(
0235                        J2eeModule.WAR)) {
0236                    Logger
0237                            .getLogger("global")
0238                            .log(Level.INFO,
0239                                    "getWebContextRoot called on other module type then WAR"); //NOI18N
0240                    return null;
0241                }
0242                if (server == null) {
0243                    return null;
0244                }
0245                ModuleConfiguration config = getModuleConfiguration();
0246                if (config == null) {
0247                    return null;
0248                }
0249
0250                try {
0251                    ContextRootConfiguration contextRootConfiguration = config
0252                            .getLookup().lookup(ContextRootConfiguration.class);
0253                    if (contextRootConfiguration != null) {
0254                        return contextRootConfiguration.getContextRoot();
0255                    }
0256                } catch (ConfigurationException ce) {
0257                    Logger.getLogger("global").log(Level.INFO, null, ce);
0258                }
0259                return null;
0260            }
0261
0262            /**
0263             * Set context root (context path)
0264             */
0265            public void setWebContextRoot(String contextRoot) {
0266                if (!getProvider().getJ2eeModule().getModuleType().equals(
0267                        J2eeModule.WAR)) {
0268                    Logger
0269                            .getLogger("global")
0270                            .log(Level.INFO,
0271                                    "setWebContextRoot called on other module type then WAR"); //NOI18N
0272                    return;
0273                }
0274                if (server == null) {
0275                    return;
0276                }
0277                ModuleConfiguration config = getModuleConfiguration();
0278                if (config == null) {
0279                    return;
0280                }
0281                try {
0282                    ContextRootConfiguration contextRootConfiguration = config
0283                            .getLookup().lookup(ContextRootConfiguration.class);
0284                    if (contextRootConfiguration != null) {
0285                        contextRootConfiguration.setContextRoot(contextRoot);
0286                    }
0287                } catch (ConfigurationException ce) {
0288                    Logger.getLogger("global").log(Level.INFO, null, ce);
0289                }
0290            }
0291
0292            public String[] getDeploymentConfigurationFileNames() {
0293                if (server == null) {
0294                    return new String[] {};
0295                }
0296                if (hasCustomSupport()) {
0297                    return (String[]) getRelativePaths().keySet().toArray(
0298                            new String[relativePaths.size()]);
0299                }
0300                return new String[] { getStandardDeploymentPlanName() };
0301            }
0302
0303            public String getContentRelativePath(String configName) {
0304                if (!hasCustomSupport()) {
0305                    return configName; //just return the name so that the .dpf file is writen at the root of dist directory.
0306                }
0307                return (String) getAllRelativePaths().get(configName);
0308            }
0309
0310            public void setCMPMappingInfo(final OriginalCMPMapping[] mappings)
0311                    throws ConfigurationException {
0312                if (server == null) {
0313                    // the module has no target server
0314                    return;
0315                }
0316                ModuleConfiguration config = getModuleConfiguration();
0317                if (config == null) {
0318                    return;
0319                }
0320                MappingConfiguration mappingConfiguration = config.getLookup()
0321                        .lookup(MappingConfiguration.class);
0322                if (mappingConfiguration != null) {
0323                    mappingConfiguration.setMappingInfo(mappings);
0324                }
0325            }
0326
0327            public void setCMPResource(String ejbName, String jndiName)
0328                    throws ConfigurationException {
0329                Parameters.notNull("ejbName", ejbName); // NOI18N
0330                Parameters.notNull("jndiName", jndiName); // NOI18N
0331                if (server == null) {
0332                    // the module has no target server
0333                    return;
0334                }
0335                ModuleConfiguration config = getModuleConfiguration();
0336                if (config == null) {
0337                    return;
0338                }
0339                MappingConfiguration mappingConfiguration = config.getLookup()
0340                        .lookup(MappingConfiguration.class);
0341                if (mappingConfiguration != null) {
0342                    mappingConfiguration.setCMPResource(ejbName, jndiName);
0343                }
0344            }
0345
0346            public Set<Datasource> getDatasources()
0347                    throws ConfigurationException {
0348
0349                Set<Datasource> projectDS = Collections.<Datasource> emptySet();
0350
0351                if (server != null) {
0352                    ModuleConfiguration config = getModuleConfiguration();
0353                    if (config != null) {
0354                        DatasourceConfiguration datasourceConfiguration = config
0355                                .getLookup().lookup(
0356                                        DatasourceConfiguration.class);
0357                        if (datasourceConfiguration != null) {
0358                            projectDS = datasourceConfiguration
0359                                    .getDatasources();
0360                        }
0361                    }
0362                }
0363
0364                return projectDS;
0365            }
0366
0367            public boolean isDatasourceCreationSupported() {
0368                if (server == null) {
0369                    // the module has no target server
0370                    return false;
0371                }
0372                ModuleConfiguration config = getModuleConfiguration();
0373                if (config != null) {
0374                    DatasourceConfiguration datasourceConfiguration = config
0375                            .getLookup().lookup(DatasourceConfiguration.class);
0376                    if (datasourceConfiguration != null) {
0377                        return datasourceConfiguration
0378                                .supportsCreateDatasource();
0379                    }
0380                }
0381                return false;
0382            }
0383
0384            public Datasource createDatasource(String jndiName, String url,
0385                    String username, String password, String driver)
0386                    throws UnsupportedOperationException,
0387                    DatasourceAlreadyExistsException {
0388                Datasource ds = null;
0389                if (server != null) {
0390                    ModuleConfiguration config = getModuleConfiguration();
0391                    if (config != null) {
0392                        DatasourceConfiguration datasourceConfiguration = config
0393                                .getLookup().lookup(
0394                                        DatasourceConfiguration.class);
0395                        if (datasourceConfiguration != null) {
0396                            try {
0397                                ds = datasourceConfiguration.createDatasource(
0398                                        jndiName, url, username, password,
0399                                        driver);
0400                            } catch (ConfigurationException ce) {
0401                                Logger.getLogger("global").log(Level.INFO,
0402                                        null, ce);
0403                            }
0404                        }
0405                    }
0406                }
0407                return ds;
0408            }
0409
0410            public void bindDatasourceReference(String referenceName,
0411                    String jndiName) throws ConfigurationException {
0412
0413                Parameters.notNull("referenceName", referenceName); // NOI18N
0414                Parameters.notNull("jndiName", jndiName); // NOI18N
0415
0416                if (server != null) {
0417                    ModuleConfiguration config = getModuleConfiguration();
0418                    if (config != null) {
0419                        DatasourceConfiguration datasourceConfiguration = config
0420                                .getLookup().lookup(
0421                                        DatasourceConfiguration.class);
0422                        if (datasourceConfiguration != null) {
0423                            datasourceConfiguration.bindDatasourceReference(
0424                                    referenceName, jndiName);
0425                        }
0426                    }
0427                }
0428            }
0429
0430            public void bindDatasourceReferenceForEjb(String ejbName,
0431                    String ejbType, String referenceName, String jndiName)
0432                    throws ConfigurationException {
0433
0434                Parameters.notNull("ejbName", ejbName); // NOI18N
0435                Parameters.notNull("ejbType", ejbType); // NOI18N
0436                Parameters.notNull("referenceName", referenceName); // NOI18N
0437                Parameters.notNull("jndiName", jndiName); // NOI18N
0438
0439                if (!EnterpriseBeans.SESSION.equals(ejbType)
0440                        && !EnterpriseBeans.ENTITY.equals(ejbType)
0441                        && !EnterpriseBeans.MESSAGE_DRIVEN.equals(ejbType)) {
0442                    throw new IllegalArgumentException(
0443                            "ejbType parameter doesn't have an allowed value.");
0444                }
0445
0446                if (server != null) {
0447                    ModuleConfiguration config = getModuleConfiguration();
0448                    if (config != null) {
0449                        DatasourceConfiguration datasourceConfiguration = config
0450                                .getLookup().lookup(
0451                                        DatasourceConfiguration.class);
0452                        if (datasourceConfiguration != null) {
0453                            datasourceConfiguration
0454                                    .bindDatasourceReferenceForEjb(ejbName,
0455                                            ejbType, referenceName, jndiName);
0456                        }
0457                    }
0458                }
0459            }
0460
0461            public String findDatasourceJndiName(String referenceName)
0462                    throws ConfigurationException {
0463
0464                Parameters.notNull("referenceName", referenceName); // NOI18N
0465
0466                String jndiName = null;
0467                if (server != null) {
0468                    ModuleConfiguration config = getModuleConfiguration();
0469                    if (config != null) {
0470                        DatasourceConfiguration datasourceConfiguration = config
0471                                .getLookup().lookup(
0472                                        DatasourceConfiguration.class);
0473                        if (datasourceConfiguration != null) {
0474                            jndiName = datasourceConfiguration
0475                                    .findDatasourceJndiName(referenceName);
0476                        }
0477                    }
0478                }
0479
0480                return jndiName;
0481            }
0482
0483            public String findDatasourceJndiNameForEjb(String ejbName,
0484                    String referenceName) throws ConfigurationException {
0485
0486                Parameters.notNull("ejbName", ejbName); // NOI18N
0487                Parameters.notNull("referenceName", referenceName); // NOI18N
0488
0489                String jndiName = null;
0490                if (server != null) {
0491                    ModuleConfiguration config = getModuleConfiguration();
0492                    if (config != null) {
0493                        DatasourceConfiguration datasourceConfiguration = config
0494                                .getLookup().lookup(
0495                                        DatasourceConfiguration.class);
0496                        if (datasourceConfiguration != null) {
0497                            jndiName = datasourceConfiguration
0498                                    .findDatasourceJndiNameForEjb(ejbName,
0499                                            referenceName);
0500                        }
0501                    }
0502                }
0503
0504                return jndiName;
0505            }
0506
0507            public Datasource findDatasource(String jndiName)
0508                    throws ConfigurationException {
0509
0510                Parameters.notNull("jndiName", jndiName); // NOI18N
0511
0512                Set<Datasource> datasources = getDatasources();
0513                for (Datasource ds : datasources) {
0514                    if (jndiName.equals(ds.getJndiName())) {
0515                        return ds;
0516                    }
0517                }
0518                datasources = provider.getServerDatasources();
0519                for (Datasource ds : datasources) {
0520                    if (jndiName.equals(ds.getJndiName())) {
0521                        return ds;
0522                    }
0523                }
0524
0525                return null;
0526            }
0527
0528            public Set<MessageDestination> getMessageDestinations()
0529                    throws ConfigurationException {
0530
0531                Set<MessageDestination> destinations = Collections
0532                        .<MessageDestination> emptySet();
0533
0534                if (server != null) {
0535                    ModuleConfiguration config = getModuleConfiguration();
0536                    if (config != null) {
0537                        MessageDestinationConfiguration msgConfig = config
0538                                .getLookup().lookup(
0539                                        MessageDestinationConfiguration.class);
0540                        if (msgConfig != null) {
0541                            destinations = msgConfig.getMessageDestinations();
0542                        }
0543                    }
0544                }
0545
0546                return destinations;
0547            }
0548
0549            public Set<MessageDestination> getServerMessageDestinations()
0550                    throws ConfigurationException {
0551                ServerInstance si = ServerRegistry.getInstance()
0552                        .getServerInstance(provider.getServerInstanceID());
0553                if (si == null) {
0554                    Logger
0555                            .getLogger("global")
0556                            .log(
0557                                    Level.WARNING,
0558                                    "The server data sources cannot be retrieved because the server instance cannot be found.");
0559                    return Collections.<MessageDestination> emptySet();
0560                }
0561
0562                return si.getMessageDestinations();
0563            }
0564
0565            public boolean supportsCreateMessageDestination() {
0566                if (server == null) {
0567                    // the module has no target server
0568                    return false;
0569                }
0570                ModuleConfiguration config = getModuleConfiguration();
0571                if (config != null) {
0572                    MessageDestinationConfiguration msgConfig = config
0573                            .getLookup().lookup(
0574                                    MessageDestinationConfiguration.class);
0575                    if (msgConfig != null) {
0576                        return msgConfig.supportsCreateMessageDestination();
0577                    }
0578                }
0579                return false;
0580            }
0581
0582            public MessageDestination createMessageDestination(String name,
0583                    MessageDestination.Type type)
0584                    throws UnsupportedOperationException,
0585                    ConfigurationException {
0586
0587                Parameters.notNull("name", name); // NOI18N
0588                Parameters.notNull("type", type); // NOI18N
0589
0590                if (server == null) {
0591                    return null;
0592                }
0593
0594                ModuleConfiguration config = getModuleConfiguration();
0595                if (config == null) {
0596                    return null;
0597                }
0598
0599                MessageDestinationConfiguration msgConfig = config.getLookup()
0600                        .lookup(MessageDestinationConfiguration.class);
0601                if (msgConfig != null) {
0602                    return msgConfig.createMessageDestination(name, type);
0603                }
0604
0605                return null;
0606            }
0607
0608            public void bindMdbToMessageDestination(String mdbName,
0609                    String name, MessageDestination.Type type)
0610                    throws ConfigurationException {
0611
0612                Parameters.notNull("mdbName", mdbName); // NOI18N
0613                Parameters.notNull("name", name); // NOI18N
0614                Parameters.notNull("type", type); // NOI18N
0615
0616                ModuleConfiguration config = getModuleConfiguration();
0617                if (server == null || config == null) {
0618                    return;
0619                }
0620
0621                MessageDestinationConfiguration msgConfig = config.getLookup()
0622                        .lookup(MessageDestinationConfiguration.class);
0623                if (msgConfig != null) {
0624                    msgConfig.bindMdbToMessageDestination(mdbName, name, type);
0625                }
0626            }
0627
0628            public String findMessageDestinationName(String mdbName)
0629                    throws ConfigurationException {
0630
0631                Parameters.notNull("mdbName", mdbName); // NOI18N
0632
0633                ModuleConfiguration config = getModuleConfiguration();
0634                if (server == null || config == null) {
0635                    return null;
0636                }
0637
0638                MessageDestinationConfiguration msgConfig = config.getLookup()
0639                        .lookup(MessageDestinationConfiguration.class);
0640                if (msgConfig != null) {
0641                    return msgConfig.findMessageDestinationName(mdbName);
0642                }
0643
0644                return null;
0645            }
0646
0647            public MessageDestination findMessageDestination(String name)
0648                    throws ConfigurationException {
0649
0650                Parameters.notNull("name", name); // NOI18N
0651
0652                Set<MessageDestination> destinations = getMessageDestinations();
0653                for (MessageDestination dest : destinations) {
0654                    if (name.equals(dest.getName())) {
0655                        return dest;
0656                    }
0657                }
0658                destinations = provider.getConfigSupport()
0659                        .getServerMessageDestinations();
0660                for (MessageDestination dest : destinations) {
0661                    if (name.equals(dest.getName())) {
0662                        return dest;
0663                    }
0664                }
0665
0666                return null;
0667            }
0668
0669            public void bindMessageDestinationReference(String referenceName,
0670                    String connectionFactoryName, String destName,
0671                    MessageDestination.Type type) throws ConfigurationException {
0672
0673                Parameters.notNull("referenceName", referenceName); // NOI18N
0674                Parameters.notNull("connectionFactoryName",
0675                        connectionFactoryName); // NOI18N
0676                Parameters.notNull("destName", destName); // NOI18N
0677                Parameters.notNull("type", type); // NOI18N
0678
0679                ModuleConfiguration config = getModuleConfiguration();
0680                if (server == null || config == null) {
0681                    return;
0682                }
0683
0684                MessageDestinationConfiguration msgConfig = config.getLookup()
0685                        .lookup(MessageDestinationConfiguration.class);
0686                if (msgConfig != null) {
0687                    msgConfig.bindMessageDestinationReference(referenceName,
0688                            connectionFactoryName, destName, type);
0689                }
0690            }
0691
0692            public void bindMessageDestinationReferenceForEjb(String ejbName,
0693                    String ejbType, String referenceName,
0694                    String connectionFactoryName, String destName,
0695                    MessageDestination.Type type) throws ConfigurationException {
0696
0697                Parameters.notNull("ejbName", ejbName); // NOI18N
0698                Parameters.notNull("ejbType", ejbType); // NOI18N
0699                Parameters.notNull("referenceName", referenceName); // NOI18N
0700                Parameters.notNull("connectionFactoryName",
0701                        connectionFactoryName); // NOI18N
0702                Parameters.notNull("destName", destName); // NOI18N
0703                Parameters.notNull("type", type); // NOI18N
0704
0705                if (!EnterpriseBeans.SESSION.equals(ejbType)
0706                        && !EnterpriseBeans.ENTITY.equals(ejbType)
0707                        && !EnterpriseBeans.MESSAGE_DRIVEN.equals(ejbType)) {
0708                    throw new IllegalArgumentException(
0709                            "ejbType parameter doesn't have an allowed value.");
0710                }
0711
0712                ModuleConfiguration config = getModuleConfiguration();
0713                if (server == null || config == null) {
0714                    return;
0715                }
0716
0717                MessageDestinationConfiguration msgConfig = config.getLookup()
0718                        .lookup(MessageDestinationConfiguration.class);
0719                if (msgConfig != null) {
0720                    msgConfig.bindMessageDestinationReferenceForEjb(ejbName,
0721                            ejbType, referenceName, connectionFactoryName,
0722                            destName, type);
0723                }
0724
0725            }
0726
0727            public String findJndiNameForEjb(String ejbName)
0728                    throws ConfigurationException {
0729                Parameters.notNull("ejbName", ejbName); // NOI18N
0730                ModuleConfiguration config = getModuleConfiguration();
0731                if (server == null || config == null) {
0732                    return null;
0733                }
0734                EjbResourceConfiguration ejbConfig = config.getLookup().lookup(
0735                        EjbResourceConfiguration.class);
0736                if (ejbConfig != null) {
0737                    return ejbConfig.findJndiNameForEjb(ejbName);
0738                }
0739                return null;
0740            }
0741
0742            public void bindEjbReference(String referenceName, String jndiName)
0743                    throws ConfigurationException {
0744
0745                Parameters.notNull("referenceName", referenceName); // NOI18N
0746                Parameters.notNull("referencedEjbName", jndiName); // NOI18N
0747
0748                ModuleConfiguration config = getModuleConfiguration();
0749                if (server == null || config == null) {
0750                    return;
0751                }
0752
0753                EjbResourceConfiguration ejbConfig = config.getLookup().lookup(
0754                        EjbResourceConfiguration.class);
0755                if (ejbConfig != null) {
0756                    ejbConfig.bindEjbReference(referenceName, jndiName);
0757                }
0758
0759            }
0760
0761            public void bindEjbReferenceForEjb(String ejbName, String ejbType,
0762                    String referenceName, String jndiName)
0763                    throws ConfigurationException {
0764
0765                Parameters.notNull("ejbName", ejbName); // NOI18N
0766                Parameters.notNull("ejbType", ejbType); // NOI18N
0767                Parameters.notNull("referenceName", referenceName); // NOI18N
0768                Parameters.notNull("referencedEjbName", jndiName); // NOI18N
0769
0770                if (!EnterpriseBeans.SESSION.equals(ejbType)
0771                        && !EnterpriseBeans.ENTITY.equals(ejbType)
0772                        && !EnterpriseBeans.MESSAGE_DRIVEN.equals(ejbType)) {
0773                    throw new IllegalArgumentException(
0774                            "ejbType parameter doesn't have an allowed value.");
0775                }
0776
0777                ModuleConfiguration config = getModuleConfiguration();
0778                if (server == null || config == null) {
0779                    return;
0780                }
0781
0782                EjbResourceConfiguration ejbConfig = config.getLookup().lookup(
0783                        EjbResourceConfiguration.class);
0784                if (ejbConfig != null) {
0785                    ejbConfig.bindEjbReferenceForEjb(ejbName, ejbType,
0786                            referenceName, jndiName);
0787                }
0788
0789            }
0790
0791            // DeploymentConfigurationProvider implementation -------------------------
0792
0793            /**
0794             * Create and cache deployment configuration for the current server.
0795             */
0796            public synchronized ModuleConfiguration getModuleConfiguration() {
0797                if (moduleConfiguration == null) {
0798                    try {
0799                        if (server == null) {
0800                            return null;
0801                        }
0802                        ModuleConfigurationFactory moduleConfigurationFactory = server
0803                                .getModuleConfigurationFactory();
0804                        moduleConfiguration = moduleConfigurationFactory
0805                                .create(j2eeModule);
0806                    } catch (ConfigurationException ce) {
0807                        Logger.getLogger("global").log(Level.INFO, null, ce);
0808                        return null;
0809                    }
0810                }
0811                return moduleConfiguration;
0812            }
0813
0814            public J2eeModule getJ2eeModule(String moduleUri) {
0815                if (j2eeModule instanceof  J2eeApplication) {
0816                    for (J2eeModule childModule : ((J2eeApplication) j2eeModule)
0817                            .getModules()) {
0818                        if (childModule.getUrl().equals(moduleUri)) {
0819                            return childModule;
0820                        }
0821                    }
0822                    // If the moduleUri is null, the j2eeModule needs to be sent back,
0823                    //     to enable directory deployment of EAR projects.
0824                    return moduleUri == null ? j2eeModule : null;
0825                }
0826                return j2eeModule;
0827            }
0828
0829            // private helpers --------------------------------------------------------
0830
0831            /**
0832             * Return list of server specific configuration files.
0833             */
0834            private static File[] getDeploymentConfigurationFiles(
0835                    J2eeModuleProvider provider, Server server,
0836                    boolean existingOnly) {
0837                if (provider == null || server == null)
0838                    return new File[0];
0839
0840                ModuleType type = (ModuleType) provider.getJ2eeModule()
0841                        .getModuleType();
0842                String[] fnames;
0843                if (hasCustomSupport(server, type)) {
0844                    fnames = server.getDeploymentPlanFiles(type);
0845                } else if (server.supportsModuleType(type)) {
0846                    fnames = new String[] { getStandardDeploymentPlanName(server) };
0847                } else {
0848                    return EMPTY_FILE_LIST;
0849                }
0850
0851                ArrayList files = new ArrayList();
0852                for (int i = 0; i < fnames.length; i++) {
0853                    File path = new File(fnames[i]);
0854                    String fname = path.getName();
0855                    File file = provider.getJ2eeModule()
0856                            .getDeploymentConfigurationFile(fname);
0857                    if (file != null && (!existingOnly || file.exists())) {
0858                        files.add(file);
0859                    }
0860                }
0861                return (File[]) files.toArray(new File[files.size()]);
0862            }
0863
0864            /**
0865             * Creates and returns the JSR-88 deployment plan file for the current 
0866             * deployment configuration.
0867             *
0868             * @return deployment plan file.
0869             */
0870            private File getDeploymentPlanFileForDistribution()
0871                    throws IOException, ConfigurationException {
0872                if (server == null) {
0873                    String msg = NbBundle.getMessage(ConfigSupportImpl.class,
0874                            "MSG_NoTargetSelected");
0875                    throw new ConfigurationException(msg);
0876                }
0877
0878                FileLock lock = null;
0879                OutputStream out = null;
0880                try {
0881                    FileObject dist = getProvider().getJ2eeModule()
0882                            .getContentDirectory();
0883                    String planName = getStandardDeploymentPlanName();
0884                    FileObject plan = null;
0885                    if (dist != null) {
0886                        plan = dist.getFileObject(planName);
0887                        if (plan == null) {
0888                            plan = dist.createData(planName);
0889                        }
0890                    } else {
0891                        return null;
0892                    }
0893                    lock = plan.lock();
0894                    out = plan.getOutputStream(lock);
0895                    ModuleConfiguration conf = getModuleConfiguration();
0896                    if (conf != null) {
0897                        DeploymentPlanConfiguration deploymentPlanConfiguration = conf
0898                                .getLookup().lookup(
0899                                        DeploymentPlanConfiguration.class);
0900                        if (deploymentPlanConfiguration != null) {
0901                            deploymentPlanConfiguration.save(out);
0902                            return FileUtil.toFile(plan);
0903                        }
0904                    }
0905                    return null;
0906                } finally {
0907                    if (lock != null)
0908                        lock.releaseLock();
0909                    try {
0910                        if (out != null)
0911                            out.close();
0912                    } catch (IOException ioe) {
0913                        Logger.getLogger("global").log(Level.INFO,
0914                                ioe.toString());
0915                    }
0916                }
0917            }
0918
0919            private String getPrimaryConfigurationFileName() {
0920                getRelativePaths();
0921
0922                if (configurationPrimaryFileName == null)
0923                    return getStandardDeploymentPlanName();
0924                else
0925                    return configurationPrimaryFileName;
0926            }
0927
0928            private String getStandardDeploymentPlanName() {
0929                return getStandardDeploymentPlanName(server);
0930
0931            }
0932
0933            private static String getStandardDeploymentPlanName(Server server) {
0934                return server.getShortName() + GENERIC_EXTENSION;
0935            }
0936
0937            private FileObject findPrimaryConfigurationFO() throws IOException {
0938                String configFileName = getPrimaryConfigurationFileName();
0939                File file = j2eeModule
0940                        .getDeploymentConfigurationFile(configFileName);
0941                return FileUtil.toFileObject(file);
0942            }
0943
0944            private ModuleType getModuleType() {
0945                return (ModuleType) getProvider().getJ2eeModule()
0946                        .getModuleType();
0947            }
0948
0949            private boolean hasCustomSupport() {
0950                return hasCustomSupport(server, getModuleType());
0951            }
0952
0953            private static boolean hasCustomSupport(Server server,
0954                    ModuleType type) {
0955                if (server == null
0956                        || server.getModuleConfigurationFactory() == null) {
0957                    return false;
0958                }
0959                return server.getDeploymentPlanFiles(type) != null;
0960            }
0961
0962            private J2eeModuleProvider getProvider() {
0963                return provider;
0964            }
0965
0966            private Map getRelativePaths() {
0967                if (relativePaths != null)
0968                    return relativePaths;
0969
0970                relativePaths = new HashMap();
0971                if (hasCustomSupport()) {
0972                    String[] paths = server
0973                            .getDeploymentPlanFiles(getModuleType());
0974                    configurationPrimaryFileName = paths[0].substring(paths[0]
0975                            .lastIndexOf("/") + 1);
0976
0977                    collectData(server, relativePaths);
0978                }
0979
0980                return relativePaths;
0981            }
0982
0983            private void collectData(Server server, Map map) {
0984                if (!this .hasCustomSupport(server, getModuleType()))
0985                    return;
0986
0987                String[] paths = server.getDeploymentPlanFiles(getModuleType());
0988                paths = (paths == null) ? new String[0] : paths;
0989                for (int i = 0; i < paths.length; i++) {
0990                    String name = paths[i]
0991                            .substring(paths[i].lastIndexOf("/") + 1);
0992                    map.put(name, paths[i]);
0993                }
0994            }
0995
0996            private Map getAllRelativePaths() {
0997                if (allRelativePaths != null)
0998                    return allRelativePaths;
0999
1000                allRelativePaths = new HashMap();
1001                Collection servers = ServerRegistry.getInstance().getServers();
1002                for (Iterator i = servers.iterator(); i.hasNext();) {
1003                    Server server = (Server) i.next();
1004                    collectData(server, allRelativePaths);
1005                }
1006                return allRelativePaths;
1007            }
1008        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.