Source Code Cross Referenced for J2eeModuleProvider.java in  » 6.0-JDK-Core » j2eeserver » org » netbeans » modules » j2ee » deployment » devmodules » spi » 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.devmodules.spi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003         *
004         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005         *
006         * The contents of this file are subject to the terms of either the GNU
007         * General Public License Version 2 only ("GPL") or the Common
008         * Development and Distribution License("CDDL") (collectively, the
009         * "License"). You may not use this file except in compliance with the
010         * License. You can obtain a copy of the License at
011         * http://www.netbeans.org/cddl-gplv2.html
012         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013         * specific language governing permissions and limitations under the
014         * License.  When distributing the software, include this License Header
015         * Notice in each file and include the License file at
016         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017         * particular file as subject to the "Classpath" exception as provided
018         * by Sun in the GPL Version 2 section of the License file that
019         * accompanied this code. If applicable, add the following below the
020         * License Header, with the fields enclosed by brackets [] replaced by
021         * your own identifying information:
022         * "Portions Copyrighted [year] [name of copyright owner]"
023         *
024         * Contributor(s):
025         *
026         * The Original Software is NetBeans. The Initial Developer of the Original
027         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028         * Microsystems, Inc. All Rights Reserved.
029         *
030         * If you wish your version of this file to be governed by only the CDDL
031         * or only the GPL Version 2, indicate your decision by adding
032         * "[Contributor] elects to include this software in this distribution
033         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034         * single choice of license, a recipient has the option to distribute
035         * your version of this file under either the CDDL, the GPL Version 2 or
036         * to extend the choice of license to its licensees as provided above.
037         * However, if you add GPL Version 2 code and therefore, elected the GPL
038         * Version 2 license, then the option applies only if the new code is
039         * made subject to such option by the copyright holder.
040         */
041
042        package org.netbeans.modules.j2ee.deployment.devmodules.spi;
043
044        import java.io.OutputStream;
045        import java.util.Collections;
046        import java.util.Iterator;
047        import java.util.Set;
048        import javax.enterprise.deploy.spi.Target;
049        import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
050        import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping;
051        import org.netbeans.modules.j2ee.deployment.common.api.ValidationException;
052        import org.netbeans.modules.j2ee.deployment.config.*;
053        import org.netbeans.modules.j2ee.deployment.devmodules.api.*;
054        import org.netbeans.modules.j2ee.deployment.impl.DefaultSourceMap;
055        import org.netbeans.modules.j2ee.deployment.impl.Server;
056        import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
057        import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
058        import org.netbeans.modules.j2ee.deployment.impl.ServerTarget;
059        import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
060        import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
061        import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
062        import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo;
063        import org.netbeans.modules.j2ee.deployment.common.api.SourceFileMap;
064        import org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer;
065        import org.netbeans.modules.j2ee.deployment.plugins.spi.VerifierSupport;
066        import org.openide.filesystems.FileObject;
067        import java.util.ArrayList;
068        import java.util.List;
069        import java.util.logging.Level;
070        import java.util.logging.Logger;
071        import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
072
073        /** This object must be implemented by J2EE module support and an instance 
074         * added into project lookup.
075         * 
076         * @author  Pavel Buzek
077         */
078        public abstract class J2eeModuleProvider {
079
080            private ConfigSupportImpl configSupportImpl;
081            final List listeners = new ArrayList();
082            private ConfigFilesListener configFilesListener = null;
083
084            public J2eeModuleProvider() {
085            }
086
087            public abstract J2eeModule getJ2eeModule();
088
089            public abstract ModuleChangeReporter getModuleChangeReporter();
090
091            public final ConfigSupport getConfigSupport() {
092                ConfigSupportImpl confSupp;
093                synchronized (this ) {
094                    confSupp = configSupportImpl;
095                }
096                if (confSupp == null) {
097                    confSupp = new ConfigSupportImpl(this );
098                    synchronized (this ) {
099                        configSupportImpl = confSupp;
100                    }
101                }
102                return confSupp;
103            }
104
105            // Do not remove this method! It is a helper for the Maven support project to 
106            // workaround the issue #109507. Please keep in mind that this is a hack, so
107            // keep it private! No one else should use it.
108            private synchronized void resetConfigSupport() {
109                configSupportImpl = null;
110            }
111
112            /**
113             * Return server debug info.
114             * Note: if server is not running and needs to be up for retrieving debug info, 
115             * this call will return null.  This call is also used by UI so it should not 
116             * try to ping or start the server.
117             */
118            public final ServerDebugInfo getServerDebugInfo() {
119                ServerInstance si = ServerRegistry.getInstance()
120                        .getServerInstance(getServerInstanceID());
121                if (si == null) {
122                    return null;
123                }
124                StartServer ss = si.getStartServer();
125                if (ss == null) {
126                    return null;
127                }
128                // AS8.1 needs to have server running to get accurate debug info, and also need a non-null target 
129                // But getting targets from AS8.1 require start server which would hang UI, so avoid start server
130                // Note: for debug info after deploy, server should already start.
131                if (!si.isRunningLastCheck() && ss.needsStartForTargetList()) {
132                    if (ss.isAlsoTargetServer(null)) {
133                        return ss.getDebugInfo(null);
134                    } else {
135                        return null;
136                    }
137                }
138
139                Target target = null;
140                ServerTarget[] sts = si.getTargets();
141                for (int i = 0; i < sts.length; i++) {
142                    if (si.getStartServer().isAlsoTargetServer(
143                            sts[i].getTarget())) {
144                        target = sts[i].getTarget();
145                    }
146                }
147                if (target == null && sts.length > 0) {
148                    target = sts[0].getTarget();
149                }
150                return si.getStartServer().getDebugInfo(target);
151            }
152
153            /**
154             * Gets the data sources deployed on the target server instance.
155             *
156             * @return set of data sources
157             * 
158             * @throws ConfigurationException reports problems in retrieving data source
159             *         definitions.
160             * 
161             * @since 1.15 
162             */
163            public Set<Datasource> getServerDatasources()
164                    throws ConfigurationException {
165                ServerInstance si = ServerRegistry.getInstance()
166                        .getServerInstance(getServerInstanceID());
167                Set<Datasource> deployedDS = Collections
168                        .<Datasource> emptySet();
169                if (si != null) {
170                    deployedDS = si.getDatasources();
171                } else {
172                    Logger
173                            .getLogger("global")
174                            .log(
175                                    Level.WARNING,
176                                    "The server data sources cannot be retrieved because the server instance cannot be found.");
177                }
178                return deployedDS;
179            }
180
181            /**
182             * Gets the data sources saved in the module.
183             *
184             * @return set of data sources
185             * 
186             * @throws ConfigurationException reports problems in retrieving data source
187             *         definitions.
188             * @since 1.15 
189             */
190            public Set<Datasource> getModuleDatasources()
191                    throws ConfigurationException {
192                Set<Datasource> projectDS = getConfigSupport().getDatasources();
193                return projectDS;
194            }
195
196            /**
197             * Tests whether data source creation is supported.
198             *
199             * @return true if data source creation is supported, false otherwise.
200             *
201             * @since 1.15 
202             */
203            public boolean isDatasourceCreationSupported() {
204                return getConfigSupport().isDatasourceCreationSupported();
205            }
206
207            /**
208             * Creates and saves data source in the module if it does not exist yet on the target server or in the module.
209             * Data source is considered to be existing when JNDI name of the found data source and the one
210             * just created equal.
211             *
212             * @param jndiName name of data source
213             * @param url database URL
214             * @param username database user
215             * @param password user's password
216             * @param driver fully qualified name of database driver class
217             * @return created data source
218             * @exception DatasourceAlreadyExistsException if conflicting data source is found
219             *
220             * @since 1.15 
221             */
222            public final Datasource createDatasource(String jndiName,
223                    String url, String username, String password, String driver)
224                    throws DatasourceAlreadyExistsException,
225                    ConfigurationException {
226
227                //check whether the ds is not already on the server
228                Set<Datasource> deployedDS = getServerDatasources();
229                if (deployedDS != null) {
230                    for (Iterator it = deployedDS.iterator(); it.hasNext();) {
231                        Datasource ds = (Datasource) it.next();
232                        if (jndiName.equals(ds.getJndiName())) // ds with the same JNDI name already exists on the server, do not create new one
233                            throw new DatasourceAlreadyExistsException(ds);
234                    }
235                }
236
237                Datasource ds = null;
238                try {
239                    //btw, ds existence in a project is verified directly in the deployment configuration
240                    ds = getConfigSupport().createDatasource(jndiName, url,
241                            username, password, driver);
242                } catch (UnsupportedOperationException oue) {
243                    Logger.getLogger("global").log(Level.INFO, null, oue);
244                }
245
246                return ds;
247            }
248
249            /**
250             * Deploys data sources saved in the module.
251             *
252             * @exception ConfigurationException if there is some problem with data source configuration
253             * @exception DatasourceAlreadyExistsException if module data source(s) are conflicting
254             * with data source(s) already deployed on the server
255             *
256             * @since 1.15 
257             */
258            public void deployDatasources() throws ConfigurationException,
259                    DatasourceAlreadyExistsException {
260                ServerInstance si = ServerRegistry.getInstance()
261                        .getServerInstance(getServerInstanceID());
262                if (si != null) {
263                    Set<Datasource> moduleDS = getModuleDatasources();
264                    si.deployDatasources(moduleDS);
265                } else {
266                    Logger
267                            .getLogger("global")
268                            .log(
269                                    Level.WARNING,
270                                    "The data sources cannot be deployed because the server instance cannot be found.");
271                }
272            }
273
274            /**
275             * Configuration support to allow development module code to access well-known 
276             * configuration propeties, such as web context root, cmp mapping info...
277             * The setters and getters work with server specific data on the server returned by
278             * {@link getServerID} method.
279             */
280            public static interface ConfigSupport {
281                /**
282                 * Create an initial fresh configuration for the current module.  Do nothing if configuration already exists.
283                 * @return true if there is no existing configuration, false if there is exsisting configuration.
284                 */
285                public boolean createInitialConfiguration();
286
287                /**
288                 * Ensure configuration is ready to respond to any editing to the module.
289                 * @return true if the configuration is ready, else false.
290                 */
291                public boolean ensureConfigurationReady();
292
293                /**
294                 * Set web module context root.
295                 * 
296                 * @param contextRoot web module context root. 
297                 * @throws ConfigurationException reports errors in setting the web context
298                 *         root.
299                 */
300                public void setWebContextRoot(String contextRoot)
301                        throws ConfigurationException;
302
303                /**
304                 * Get web module context root.
305                 * 
306                 * @return web module context root.
307                 * 
308                 * @throws ConfigurationException reports errors in setting the web context
309                 *         root.
310                 */
311                public String getWebContextRoot() throws ConfigurationException;
312
313                /**
314                 * Return a list of file names for current server specific deployment 
315                 * descriptor used in this module.
316                 */
317                public String[] getDeploymentConfigurationFileNames();
318
319                /**
320                 * Return relative path within the archive or distribution content for the
321                 * given server specific deployment descriptor file.
322                 * @param deploymentConfigurationFileName server specific descriptor file name
323                 * @return relative path inside distribution content.
324                 */
325                public String getContentRelativePath(
326                        String deploymentConfigurationFileName);
327
328                /**
329                 * Push the CMP and CMR mapping info to the server configuraion.
330                 * This call is typically used by CMP mapping wizard.
331                 * 
332                 * @throws ConfigurationException reports errors in setting the CMP mapping.
333                 */
334                public void setCMPMappingInfo(OriginalCMPMapping[] mappings)
335                        throws ConfigurationException;
336
337                /**
338                 * Sets the resource for the specified CMP bean. Some containers may not 
339                 * support fine-grained per bean resource definition, in which case global 
340                 * EJB module CMP resource is set.
341                 *
342                 * @param ejbName   name of the CMP bean.
343                 * @param jndiName  the JNDI name of the resource.
344                 * 
345                 * @throws ConfigurationException reports errors in setting the CMP resource.
346                 * @throws NullPointerException if any of the parameters is <code>null</code>.
347                 * 
348                 * @since 1.30
349                 */
350                void setCMPResource(String ejbName, String jndiName)
351                        throws ConfigurationException;
352
353                /**
354                 * Tests whether data source creation is supported.
355                 *
356                 * @return true if data source creation is supported, false otherwise.
357                 *
358                 * @since 1.15 
359                 */
360                public boolean isDatasourceCreationSupported();
361
362                /**
363                 * Gets the data sources saved in the module.
364                 *
365                 * @return set of data sources
366                 *
367                 * @throws ConfigurationException reports errors in retrieving the data sources.
368                 * 
369                 * @since 1.15 
370                 * 
371                 */
372                public Set<Datasource> getDatasources()
373                        throws ConfigurationException;
374
375                /**
376                 * Creates and saves data source in the module if it does not exist yet in the module.
377                 * Data source is considered to be existing when JNDI name of the found data source and the one
378                 * just created equal.
379                 *
380                 * @param jndiName name of data source
381                 * @param url database URL
382                 * @param username database user
383                 * @param password user's password
384                 * @param driver fully qualified name of database driver class
385                 * 
386                 * @return created data source
387                 * 
388                 * @throws UnsupportedOperationException if operation is not supported
389                 * @throws DatasourceAlreadyExistsException if conflicting data source is found
390                 * @throws ConfigurationException reports errors in creating the data source.
391                 *
392                 * @since 1.15 
393                 */
394                public Datasource createDatasource(String jndiName, String url,
395                        String username, String password, String driver)
396                        throws UnsupportedOperationException,
397                        DatasourceAlreadyExistsException,
398                        ConfigurationException;
399
400                /**
401                 * Binds the data source reference name with the corresponding data source which is
402                 * identified by the given JNDI name.
403                 * 
404                 * @param referenceName name used to identify the data source
405                 * @param jndiName JNDI name of the data source
406                 * 
407                 * @throws NullPointerException if any of parameters is null
408                 * @throws ConfigurationException if there is some problem with data source configuration
409                 * 
410                 * @since 1.25
411                 */
412                public void bindDatasourceReference(String referenceName,
413                        String jndiName) throws ConfigurationException;
414
415                /**
416                 * Binds the data source reference name with the corresponding data source which is
417                 * identified by the given JNDI name. The reference is used within the scope of the EJB.
418                 * 
419                 * @param ejbName EJB name
420                 * @param ejbType EJB type - the possible values are 
421                 *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION,
422                 *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY and
423                 *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN
424                 * @param referenceName name used to identify the data source
425                 * @param jndiName JNDI name of the data source
426
427                 * @throws NullPointerException if any of parameters is null
428                 * @throws ConfigurationException if there is some problem with data source configuration
429                 * @throws IllegalArgumentException if ejbType doesn't have one of allowed values
430                 * 
431                 * @since 1.25
432                 */
433                public void bindDatasourceReferenceForEjb(String ejbName,
434                        String ejbType, String referenceName, String jndiName)
435                        throws ConfigurationException;
436
437                /**
438                 * Finds JNDI name of data source which is mapped to the given reference name of a data source
439                 * 
440                 * @param referenceName reference name of data source
441                 * @return JNDI name which is mapped to the given JNDI name
442                 * 
443                 * @throws NullPointerException if reference name is null
444                 * @throws ConfigurationException if there is some problem with data source configuration
445                 * 
446                 * @since 1.25
447                 */
448                public String findDatasourceJndiName(String referenceName)
449                        throws ConfigurationException;
450
451                /**
452                 * Finds JNDI name of data source which is mapped to the given reference name in the scope of the EJB.
453                 * 
454                 * @param ejbName EJB name
455                 * @param referenceName reference name of data source
456                 * @return data source if it exists, null otherwise
457                 *
458                 * @throws NullPointerException if any of parameters is null
459                 * @throws ConfigurationException if there is some problem with data source configuration
460                 * 
461                 * @since 1.25
462                 */
463                public String findDatasourceJndiNameForEjb(String ejbName,
464                        String referenceName) throws ConfigurationException;
465
466                /**
467                 * Finds data source with the given JNDI name.
468                 * 
469                 * @param jndiName JNDI name of a data source
470                 * @param return data source if it exists, null otherwise
471                 *
472                 * @throws NullPointerException if JNDI name is null
473                 * @throws ConfigurationException if there is some problem with data source configuration
474                 * 
475                 * @since 1.25
476                 */
477                public Datasource findDatasource(String jndiName)
478                        throws ConfigurationException;
479
480                /**
481                 * Retrieves message destinations stored in the module.
482                 * 
483                 * @return set of message destinations
484                 * 
485                 * @throws ConfigurationException if there is some problem with message destination configuration
486                 * 
487                 * @since 1.25
488                 */
489                public Set<MessageDestination> getMessageDestinations()
490                        throws ConfigurationException;
491
492                /**
493                 * Retrieves message destinations configured on the target server instance.
494                 *
495                 * @return set of message destinations
496                 * 
497                 * @throws ConfigurationException if there is some problem with message destination configuration
498                 * 
499                 * @since 1.25 
500                 */
501                public Set<MessageDestination> getServerMessageDestinations()
502                        throws ConfigurationException;
503
504                /**
505                 * Tests whether a message destination creation is supported.
506                 *
507                 * @return true if message destination creation is supported, false otherwise.
508                 *
509                 * @since 1.25
510                 */
511                public boolean supportsCreateMessageDestination();
512
513                /**
514                 * Creates and saves a message destination in the module if it does not exist in the module yet.
515                 * Message destinations are considered to be equal if their JNDI names are equal.
516                 *
517                 * @param name name of the message destination
518                 * @param type message destination type
519                 * @return created message destination
520                 * 
521                 * @throws NullPointerException if any of parameters is null
522                 * @throws UnsupportedOperationException if this opearation is not supported
523                 * @throws ConfigurationException if there is some problem with message destination configuration
524                 *
525                 * @since 1.25 
526                 */
527                public MessageDestination createMessageDestination(String name,
528                        MessageDestination.Type type)
529                        throws UnsupportedOperationException,
530                        ConfigurationException;
531
532                /**
533                 * Binds the message destination name with message-driven bean.
534                 * 
535                 * @param mdbName MDB name
536                 * @param name name of the message destination
537                 * @param type message destination type
538                 * 
539                 * @throws NullPointerException if any of parameters is null
540                 * @throws ConfigurationException if there is some problem with message destination configuration
541                 * 
542                 * @since 1.25
543                 */
544                public void bindMdbToMessageDestination(String mdbName,
545                        String name, MessageDestination.Type type)
546                        throws ConfigurationException;
547
548                /**
549                 * Finds name of message destination which the given MDB listens to
550                 * 
551                 * @param mdbName MDB name
552                 * @return message destination name
553                 * 
554                 * @throws NullPointerException if MDB name is null
555                 * @throws ConfigurationException if there is some problem with message destination configuration
556                 * 
557                 * @since 1.25
558                 */
559                public String findMessageDestinationName(String mdbName)
560                        throws ConfigurationException;
561
562                /**
563                 * Finds message destination with the given name.
564                 * 
565                 * @param name message destination name
566                 * @param return message destination if it exists, null otherwise
567                 *
568                 * @throws NullPointerException if name is null
569                 * @throws ConfigurationException if there is some problem with message destination configuration
570                 * 
571                 * @since 1.25
572                 */
573                public MessageDestination findMessageDestination(String name)
574                        throws ConfigurationException;
575
576                /**
577                 * Binds the message destination reference name with the corresponding message destination which is
578                 * identified by the given name.
579                 * 
580                 * @param referenceName reference name used to identify the message destination
581                 * @param connectionFactoryName connection factory name
582                 * @param destName name of the message destination
583                 * @param type message destination type
584                 * 
585                 * @throws NullPointerException if any of parameters is null
586                 * @throws ConfigurationException if there is some problem with message destination configuration
587                 * 
588                 * @since 1.25
589                 */
590                public void bindMessageDestinationReference(
591                        String referenceName, String connectionFactoryName,
592                        String destName, MessageDestination.Type type)
593                        throws ConfigurationException;
594
595                /**
596                 * Binds the message destination reference name with the corresponding message destination which is
597                 * identified by the given name. The reference is used within the EJB scope.
598                 * 
599                 * @param ejbName EJB name
600                 * @param ejbType EJB type - the possible values are 
601                 *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION,
602                 *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY and
603                 *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN
604                 * @param referenceName reference name used to identify the message destination
605                 * @param connectionFactoryName connection factory name
606                 * @param destName name of the message destination
607                 * @param type message destination type
608                 * 
609                 * @throws NullPointerException if any of parameters is null
610                 * @throws ConfigurationException if there is some problem with message destination configuration
611                 * @throws IllegalArgumentException if ejbType doesn't have one of allowed values
612                 * 
613                 * @since 1.25
614                 */
615                public void bindMessageDestinationReferenceForEjb(
616                        String ejbName, String ejbType, String referenceName,
617                        String connectionFactoryName, String destName,
618                        MessageDestination.Type type)
619                        throws ConfigurationException;
620
621                /**
622                 * Returns a JNDI name for the given EJB or <code>null</code> if the EJB has 
623                 * no JNDI name assigned.
624                 *
625                 * @param  ejbName EJB name
626                 * 
627                 * @return JNDI name bound to the EJB or <code>null</code> if the EJB has no 
628                 *         JNDI name assigned.
629                 * 
630                 * @throws ConfigurationException if there is some problem with EJB configuration.
631                 * 
632                 * @since 1.33
633                 */
634                public String findJndiNameForEjb(String ejbName)
635                        throws ConfigurationException;
636
637                /**
638                 * Binds EJB reference name with EJB name.
639                 * 
640                 * @param referenceName name used to identify the EJB
641                 * @param jndiName JNDI name of the referenced EJB
642                 * 
643                 * @throws NullPointerException if any of parameters is null
644                 * @throws ConfigurationException if there is some problem with EJB configuration
645                 * 
646                 * @since 1.26
647                 */
648                public void bindEjbReference(String referenceName,
649                        String jndiName) throws ConfigurationException;
650
651                /**
652                 * Binds EJB reference name with EJB name within the EJB scope.
653                 * 
654                 * @param ejbName EJB name
655                 * @param ejbType EJB type - the possible values are 
656                 *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION,
657                 *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY and
658                 *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN
659                 * @param referenceName name used to identify the referenced EJB
660                 * @param jndiName JNDI name of the referenced EJB
661                 * 
662                 * @throws NullPointerException if any of parameters is null
663                 * @throws ConfigurationException if there is some problem with EJB configuration
664                 * @throws IllegalArgumentException if ejbType doesn't have one of allowed values
665                 * 
666                 * @since 1.26
667                 */
668                public void bindEjbReferenceForEjb(String ejbName,
669                        String ejbType, String referenceName, String jndiName)
670                        throws ConfigurationException;
671            }
672
673            /**
674             *  Returns list of root directories for source files including configuration files.
675             *  Examples: file objects for src/java, src/conf.  
676             *  Note: 
677             *  If there is a standard configuration root, it should be the first one in
678             *  the returned list.
679             */
680            public FileObject[] getSourceRoots() {
681                return new FileObject[0];
682            }
683
684            /**
685             * Return destination path-to-source file mappings.
686             * Default returns config file mapping with straight mapping from the configuration
687             * directory to distribution directory.
688             */
689            public SourceFileMap getSourceFileMap() {
690                return new DefaultSourceMap(this );
691            }
692
693            /** If the module wants to specify a target server instance for deployment 
694             * it needs to override this method to return false. 
695             */
696            public boolean useDefaultServer() {
697                return true;
698            }
699
700            /**
701             * Set ID of the server instance that will be used for deployment.
702             * 
703             * @param severInstanceID server instance ID.
704             * @since 1.6
705             */
706            public abstract void setServerInstanceID(String severInstanceID);
707
708            /** Id of server isntance for deployment. The default implementation returns
709             * the default server instance selected in Server Registry. 
710             * The return value may not be null.
711             * If modules override this method they also need to override {@link useDefaultServer}.
712             */
713            public String getServerInstanceID() {
714                return ServerRegistry.getInstance().getDefaultInstance()
715                        .getUrl();
716            }
717
718            /**
719             * Return InstanceProperties of the server instance
720             **/
721            public InstanceProperties getInstanceProperties() {
722                return InstanceProperties
723                        .getInstanceProperties(getServerInstanceID());
724            }
725
726            /** This method is used to determin type of target server.
727             * The return value must correspond to value returned from {@link getServerInstanceID}.
728             */
729            public String getServerID() {
730                return ServerRegistry.getInstance().getDefaultInstance()
731                        .getServer().getShortName();
732            }
733
734            /**
735             * Return name to be used in deployment of the module.
736             */
737            public String getDeploymentName() {
738                return getConfigSupportImpl().getDeploymentName();
739            }
740
741            /**
742             * Returns true if the current target platform provide verifier support for this module.
743             */
744            public boolean hasVerifierSupport() {
745                String serverId = getServerID();
746                if (serverId != null) {
747                    Server server = ServerRegistry.getInstance().getServer(
748                            serverId);
749                    if (server != null) {
750                        return server
751                                .canVerify(getJ2eeModule().getModuleType());
752                    }
753                }
754                return false;
755            }
756
757            /**
758             * Invoke verifier from current platform on the provided target file.
759             * @param target File to run verifier against.
760             * @param logger output stream to write verification resutl to.
761             * @return true
762             */
763            public void verify(FileObject target, OutputStream logger)
764                    throws ValidationException {
765                VerifierSupport verifier = ServerRegistry.getInstance()
766                        .getServer(getServerID()).getVerifierSupport();
767                if (verifier == null) {
768                    throw new ValidationException(
769                            "Verification not supported by the selected server");
770                }
771                Object type = getJ2eeModule().getModuleType();
772                if (!verifier.supportsModuleType(type)) {
773                    throw new ValidationException(
774                            "Verification not supported for module type "
775                                    + type);
776                }
777                ServerRegistry.getInstance().getServer(getServerID())
778                        .getVerifierSupport().verify(target, logger);
779            }
780
781            // TODO project should handle this
782            protected final void fireServerChange(String oldServerID,
783                    String newServerID) {
784                Server oldServer = ServerRegistry.getInstance().getServer(
785                        oldServerID);
786                Server newServer = ServerRegistry.getInstance().getServer(
787                        newServerID);
788
789                // corresponds to the "resolve missing server" or "new project"
790                if (oldServer == null && newServer != null) {
791                    ConfigSupportImpl oldConSupp;
792                    synchronized (this ) {
793                        oldConSupp = configSupportImpl;
794                        configSupportImpl = null;
795                    }
796
797                    if (oldConSupp != null) {
798                        /**
799                         * Only if we are resolving the missing server we create the
800                         * configuration. In fact this shouldn't hurt anything if we
801                         * did it always, but some plugins print some annoying messages.
802                         * However oldConSupp not null condition could be fragile.
803                         */
804                        getConfigSupportImpl().ensureConfigurationReady();
805                        oldConSupp.dispose();
806                    }
807                    return;
808                }
809
810                // corresponds to switching from one server to another, both existing
811                if (oldServer != null && newServer != null
812                        && !newServer.equals(oldServer)) {
813
814                    if (J2eeModule.WAR.equals(getJ2eeModule().getModuleType())) {
815                        String oldCtxPath = getConfigSupportImpl()
816                                .getWebContextRoot();
817                        ConfigSupportImpl oldConSupp;
818                        synchronized (this ) {
819                            oldConSupp = configSupportImpl;
820                            configSupportImpl = null;
821                        }
822                        getConfigSupportImpl().ensureConfigurationReady();
823
824                        if (oldCtxPath == null || oldCtxPath.equals("")) { //NOI18N
825                            oldCtxPath = getDeploymentName().replace(' ', '_'); //NOI18N
826                            char c[] = oldCtxPath.toCharArray();
827                            for (int i = 0; i < c.length; i++) {
828                                if (!Character.UnicodeBlock.BASIC_LATIN
829                                        .equals(Character.UnicodeBlock.of(c[i]))
830                                        || !Character.isLetterOrDigit(c[i])) {
831                                    c[i] = '_';
832                                }
833                            }
834                            oldCtxPath = "/" + new String(c); //NOI18N
835                        }
836                        getConfigSupportImpl().setWebContextRoot(oldCtxPath);
837
838                        if (oldConSupp != null) {
839                            oldConSupp.dispose();
840                        }
841                    } else {
842                        ConfigSupportImpl oldConSupp;
843                        synchronized (this ) {
844                            oldConSupp = configSupportImpl;
845                            configSupportImpl = null;
846                        }
847                        getConfigSupportImpl().ensureConfigurationReady();
848                        if (oldConSupp != null) {
849                            oldConSupp.dispose();
850                        }
851                    }
852                }
853            }
854
855            /**
856             * Returns all configuration files known to this J2EE Module.
857             */
858            public final FileObject[] getConfigurationFiles() {
859                return getConfigurationFiles(false);
860            }
861
862            public final FileObject[] getConfigurationFiles(boolean refresh) {
863                if (refresh) {
864                    configFilesListener.stopListening();
865                    configFilesListener = null;
866                }
867                addCFL();
868                return ConfigSupportImpl.getConfigurationFiles(this );
869            }
870
871            public final void addConfigurationFilesListener(
872                    ConfigurationFilesListener l) {
873                listeners.add(l);
874            }
875
876            public final void removeConfigurationFilesListener(
877                    ConfigurationFilesListener l) {
878                listeners.remove(l);
879            }
880
881            /**
882             * Register an instance listener that will listen to server instances changes.
883             *
884             * @l listener which should be added.
885             *
886             * @since 1.6
887             */
888            public final void addInstanceListener(InstanceListener l) {
889                ServerRegistry.getInstance().addInstanceListener(l);
890            }
891
892            /**
893             * Remove an instance listener which has been registered previously.
894             *
895             * @l listener which should be removed.
896             *
897             * @since 1.6
898             */
899            public final void removeInstanceListener(InstanceListener l) {
900                ServerRegistry.getInstance().removeInstanceListener(l);
901            }
902
903            private void addCFL() {
904                //already listen
905                if (configFilesListener != null)
906                    return;
907                configFilesListener = new ConfigFilesListener(this , listeners);
908            }
909
910            private ConfigSupportImpl getConfigSupportImpl() {
911                return (ConfigSupportImpl) getConfigSupport();
912            }
913
914        }
w__w_w___.j_av__a__2s._c__o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.