This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 93815
Collapse All | Expand All

(-)j2eeserver/apichanges.xml (+18 lines)
Lines 86-91 Link Here
86
    <!-- ACTUAL CHANGES BEGIN HERE: -->
86
    <!-- ACTUAL CHANGES BEGIN HERE: -->
87
87
88
    <changes>
88
    <changes>
89
        <change id="ResourceApiRedesign">
90
            <api name="j2eeserver"/>
91
            <summary>
92
                Adding an API for working with data sources, message-driven beans and JMS messages
93
            </summary>
94
            <version major="1" minor="25"/>
95
            <date day="05" month="4" year="2007"/>
96
            <author login="lkotouc"/>
97
            <compatibility binary="incompatible" source="incompatible" semantic="incompatible" addition="yes"/>
98
            <description>
99
                <p>
100
                    API for working with data sources, message-driven beans and JMS messages.
101
            	</p>
102
            </description>
103
            <class package="org.netbeans.modules.j2ee.deployment.plugins.spi" name="JDBCDriverDeployer"/>
104
            <class package="org.netbeans.modules.j2ee.deployment.plugins.spi" name="OptionalDeploymentManagerFactory"/>
105
            <issue number="89439"/>
106
        </change>
89
        <change id="jdbcDriverDeployment">
107
        <change id="jdbcDriverDeployment">
90
            <api name="j2eeserver"/>
108
            <api name="j2eeserver"/>
91
            <summary>
109
            <summary>
(-)j2eeserver/nbproject/project.properties (-1 / +1 lines)
Lines 17-23 Link Here
17
17
18
is.autoload=true
18
is.autoload=true
19
javac.source=1.5
19
javac.source=1.5
20
spec.version.base=1.24.0
20
spec.version.base=1.25.0
21
21
22
javadoc.overview=${basedir}/api/doc/overview.html
22
javadoc.overview=${basedir}/api/doc/overview.html
23
javadoc.arch=${basedir}/arch.xml
23
javadoc.arch=${basedir}/arch.xml
(-)j2eeserver/src/org/netbeans/modules/j2ee/deployment/common/api/MessageDestination.java (+59 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.j2ee.deployment.common.api;
21
22
/**
23
 * Represents a message destination
24
 *
25
 * @author Libor Kotouc
26
 *
27
 * @since 1.25
28
 */
29
public interface MessageDestination {
30
    
31
    /**
32
     * Message destination type
33
     */
34
    public enum Type {
35
        /**
36
         * Queue
37
         */ 
38
        QUEUE, 
39
        
40
        /**
41
         * Topic
42
         */
43
        TOPIC
44
    };
45
    
46
    /**
47
     * Returns the name
48
     *
49
     * @return the name
50
     */
51
    public String getName();
52
    
53
    /**
54
     * Returns the type
55
     * 
56
     * @return the type
57
     */
58
    public Type getType();
59
}
(-)j2eeserver/src/org/netbeans/modules/j2ee/deployment/config/ConfigSupportImpl.java (-7 / +266 lines)
Lines 13-26 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
19
20
package org.netbeans.modules.j2ee.deployment.config;
20
package org.netbeans.modules.j2ee.deployment.config;
21
21
22
import java.beans.PropertyChangeEvent;
23
import java.beans.PropertyChangeListener;
24
import java.io.File;
22
import java.io.File;
25
import java.io.IOException;
23
import java.io.IOException;
26
import java.io.OutputStream;
24
import java.io.OutputStream;
Lines 31-43 Link Here
31
import java.util.Iterator;
29
import java.util.Iterator;
32
import java.util.Map;
30
import java.util.Map;
33
import java.util.Set;
31
import java.util.Set;
34
import javax.enterprise.deploy.model.DDBean;
35
import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException;
36
import org.netbeans.modules.j2ee.dd.api.common.ComponentInterface;
32
import org.netbeans.modules.j2ee.dd.api.common.ComponentInterface;
37
import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping;
33
import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping;
38
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeApplication;
34
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeApplication;
39
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
35
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
40
import org.netbeans.modules.j2ee.deployment.execution.ModuleConfigurationProvider;
41
import org.netbeans.modules.j2ee.deployment.impl.Server;
36
import org.netbeans.modules.j2ee.deployment.impl.Server;
42
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
37
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
43
import javax.enterprise.deploy.shared.ModuleType;
38
import javax.enterprise.deploy.shared.ModuleType;
Lines 60-66 Link Here
60
import org.openide.util.NbBundle;
55
import org.openide.util.NbBundle;
61
import org.netbeans.api.project.FileOwnerQuery;
56
import org.netbeans.api.project.FileOwnerQuery;
62
import org.netbeans.api.project.Project;
57
import org.netbeans.api.project.Project;
58
import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
59
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
63
import org.netbeans.modules.j2ee.deployment.execution.ModuleConfigurationProvider;
60
import org.netbeans.modules.j2ee.deployment.execution.ModuleConfigurationProvider;
61
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.MessageDestinationConfiguration;
62
import org.openide.util.Parameters;
64
63
65
/**
64
/**
66
 * Each J2eeModuleProvider hold a reference to an instance of this config support.
65
 * Each J2eeModuleProvider hold a reference to an instance of this config support.
Lines 374-380 Link Here
374
    }
373
    }
375
    
374
    
376
    public Datasource createDatasource(String jndiName, String  url, String username, String password, String driver) 
375
    public Datasource createDatasource(String jndiName, String  url, String username, String password, String driver) 
377
    throws OperationUnsupportedException, DatasourceAlreadyExistsException {
376
    throws UnsupportedOperationException, DatasourceAlreadyExistsException {
378
        Datasource ds = null;
377
        Datasource ds = null;
379
        if (server != null) {
378
        if (server != null) {
380
            ModuleConfiguration config = getModuleConfiguration();
379
            ModuleConfiguration config = getModuleConfiguration();
Lines 391-396 Link Here
391
        }
390
        }
392
        return ds;
391
        return ds;
393
    }    
392
    }    
393
    
394
    public void bindDatasourceReference(String referenceName, String jndiName) throws ConfigurationException {
395
396
        Parameters.notNull("referenceName", referenceName);     // NOI18N
397
        Parameters.notNull("jndiName", jndiName);               // NOI18N
398
        
399
        if (server != null) {
400
            ModuleConfiguration config = getModuleConfiguration();
401
            if (config != null) {
402
                DatasourceConfiguration datasourceConfiguration = config.getLookup().lookup(DatasourceConfiguration.class);
403
                if (datasourceConfiguration != null) {
404
                    datasourceConfiguration.bindDatasourceReference(referenceName, jndiName);
405
                }
406
            }
407
        }
408
   }
409
410
    public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, 
411
            String referenceName, String jndiName) throws ConfigurationException {
412
        
413
        Parameters.notNull("ejbName", ejbName);             // NOI18N
414
        Parameters.notNull("ejbType", ejbType);             // NOI18N
415
        Parameters.notNull("referenceName", referenceName); // NOI18N
416
        Parameters.notNull("jndiName", jndiName);           // NOI18N
417
        
418
        if (!EnterpriseBeans.SESSION.equals(ejbType) &&
419
            !EnterpriseBeans.ENTITY.equals(ejbType) &&
420
            !EnterpriseBeans.MESSAGE_DRIVEN.equals(ejbType)) {
421
            throw new IllegalArgumentException("ejbType parameter doesn't have an allowed value.");
422
        }
423
        
424
        if (server != null) {
425
            ModuleConfiguration config = getModuleConfiguration();
426
            if (config != null) {
427
                DatasourceConfiguration datasourceConfiguration = config.getLookup().lookup(DatasourceConfiguration.class);
428
                if (datasourceConfiguration != null) {
429
                    datasourceConfiguration.bindDatasourceReferenceForEjb(ejbName, ejbType, referenceName, jndiName);
430
                }
431
            }
432
        }
433
    }
434
435
    public String findDatasourceJndiName(String referenceName) throws ConfigurationException {
436
        
437
        Parameters.notNull("referenceName", referenceName); // NOI18N
438
        
439
        String jndiName = null;
440
        if (server != null) {
441
            ModuleConfiguration config = getModuleConfiguration();
442
            if (config != null) {
443
                DatasourceConfiguration datasourceConfiguration = config.getLookup().lookup(DatasourceConfiguration.class);
444
                if (datasourceConfiguration != null) {
445
                    jndiName = datasourceConfiguration.findDatasourceJndiName(referenceName);
446
                }
447
            }
448
        }
449
        
450
        return jndiName;
451
    }
452
453
    public String findDatasourceJndiNameForEjb(String ejbName, String referenceName) throws ConfigurationException {
454
455
        Parameters.notNull("ejbName", ejbName);             // NOI18N
456
        Parameters.notNull("referenceName", referenceName); // NOI18N
457
458
        String jndiName = null;
459
        if (server != null) {
460
            ModuleConfiguration config = getModuleConfiguration();
461
            if (config != null) {
462
                DatasourceConfiguration datasourceConfiguration = config.getLookup().lookup(DatasourceConfiguration.class);
463
                if (datasourceConfiguration != null) {
464
                    jndiName = datasourceConfiguration.findDatasourceJndiNameForEjb(ejbName, referenceName);
465
                }
466
            }
467
        }
468
        
469
        return jndiName;
470
    }
471
472
    public Datasource findDatasource(String jndiName) throws ConfigurationException {
473
        
474
        Parameters.notNull("jndiName", jndiName);           // NOI18N
475
476
        Set<Datasource> datasources = getDatasources();
477
        for (Datasource ds : datasources) {
478
            if (jndiName.equals(ds.getJndiName())) {
479
                return ds;
480
            }
481
        }
482
        datasources = provider.getServerDatasources();
483
        for (Datasource ds : datasources) {
484
            if (jndiName.equals(ds.getJndiName())) {
485
                return ds;
486
            }
487
        }
488
        
489
        return null;
490
    }
491
492
    public Set<MessageDestination> getMessageDestinations() throws ConfigurationException {
493
        
494
        Set<MessageDestination> destinations = Collections.<MessageDestination>emptySet();
495
        
496
        if (server != null) {
497
            ModuleConfiguration config = getModuleConfiguration();
498
            if (config != null) {
499
                MessageDestinationConfiguration msgConfig = config.getLookup().lookup(MessageDestinationConfiguration.class);
500
                if (msgConfig != null) {
501
                    destinations = msgConfig.getMessageDestinations();
502
                }
503
            }
504
        }
505
506
        return destinations;
507
    }
508
509
    public Set<MessageDestination> getServerMessageDestinations() throws ConfigurationException {
510
        ServerInstance si = ServerRegistry.getInstance().getServerInstance(provider.getServerInstanceID());
511
        if (si == null) {
512
            ErrorManager.getDefault().log(ErrorManager.WARNING, 
513
                    "The server data sources cannot be retrieved because the server instance cannot be found.");
514
            return Collections.<MessageDestination>emptySet();
515
        }
516
        
517
        return si.getMessageDestinations();
518
   }
519
    
520
    public boolean supportsCreateMessageDestination() {
521
        if (server == null) {
522
            // the module has no target server
523
            return false;
524
        }
525
        ModuleConfiguration config = getModuleConfiguration();
526
        if (config != null) {
527
            MessageDestinationConfiguration msgConfig = config.getLookup().lookup(MessageDestinationConfiguration.class);
528
            if (msgConfig != null) {
529
                return msgConfig.supportsCreateMessageDestination();
530
            }
531
        }
532
        return false;
533
    }
534
535
    public MessageDestination createMessageDestination(String name, MessageDestination.Type type) 
536
    throws UnsupportedOperationException, ConfigurationException {
537
        
538
        Parameters.notNull("name", name);           // NOI18N
539
        Parameters.notNull("type", type);           // NOI18N
540
        
541
        if (server == null) {
542
            return null;
543
        }
544
         
545
        ModuleConfiguration config = getModuleConfiguration();
546
        if (config == null) {
547
            return null;
548
        }
549
        
550
        MessageDestinationConfiguration msgConfig = config.getLookup().lookup(MessageDestinationConfiguration.class);
551
        if (msgConfig != null) {
552
            return msgConfig.createMessageDestination(name, type);
553
        }
554
555
        return null;
556
    }
557
    
558
    public void bindMdbToMessageDestination(String mdbName, String name, MessageDestination.Type type) throws ConfigurationException {
559
        
560
        Parameters.notNull("mdbName", mdbName);     // NOI18N
561
        Parameters.notNull("name", name);           // NOI18N
562
        Parameters.notNull("type", type);           // NOI18N
563
564
        ModuleConfiguration config = getModuleConfiguration();
565
        if (server == null || config == null) {
566
            return;
567
        }
568
        
569
        MessageDestinationConfiguration msgConfig = config.getLookup().lookup(MessageDestinationConfiguration.class);
570
        if (msgConfig != null) {
571
            msgConfig.bindMdbToMessageDestination(mdbName, name, type);
572
        }
573
    }
574
575
    public String findMessageDestinationName(String mdbName) throws ConfigurationException {
576
        
577
        Parameters.notNull("mdbName", mdbName);     // NOI18N
578
        
579
        ModuleConfiguration config = getModuleConfiguration();
580
        if (server == null || config == null) {
581
            return null;
582
        }
583
        
584
        MessageDestinationConfiguration msgConfig = config.getLookup().lookup(MessageDestinationConfiguration.class);
585
        if (msgConfig != null) {
586
            return msgConfig.findMessageDestinationName(mdbName);
587
        }
588
        
589
        return null;
590
    }
591
    
592
    public MessageDestination findMessageDestination(String name) throws ConfigurationException {
593
        
594
        Parameters.notNull("name", name);     // NOI18N
595
596
        Set<MessageDestination> destinations = getMessageDestinations();
597
        for (MessageDestination dest : destinations) {
598
            if (name.equals(dest.getName())) {
599
                return dest;
600
            }
601
        }
602
        destinations = provider.getConfigSupport().getServerMessageDestinations();
603
        for (MessageDestination dest : destinations) {
604
            if (name.equals(dest.getName())) {
605
                return dest;
606
            }
607
        }
608
        
609
        return null;
610
    }
611
612
    public void bindMessageDestinationReference(String referenceName, String connectionFactoryName, 
613
            String destName, MessageDestination.Type type) throws ConfigurationException {
614
        
615
        Parameters.notNull("referenceName", referenceName);                 // NOI18N
616
        Parameters.notNull("connectionFactoryName", connectionFactoryName); // NOI18N
617
        Parameters.notNull("destName", destName);                           // NOI18N
618
        Parameters.notNull("type", type);                                   // NOI18N
619
        
620
        ModuleConfiguration config = getModuleConfiguration();
621
        if (server == null || config == null) {
622
            return;
623
        }
624
        
625
        MessageDestinationConfiguration msgConfig = config.getLookup().lookup(MessageDestinationConfiguration.class);
626
        if (msgConfig != null) {
627
            msgConfig.bindMessageDestinationReference(referenceName, connectionFactoryName, destName, type);
628
        }
629
    }
630
631
    public void bindMessageDestinationReferenceForEjb(String ejbName, String ejbType,
632
            String referenceName, String connectionFactoryName,
633
            String destName, MessageDestination.Type type) throws ConfigurationException {
634
        
635
        Parameters.notNull("ejbName", ejbName);             // NOI18N
636
        Parameters.notNull("ejbType", ejbType);             // NOI18N
637
        Parameters.notNull("referenceName", referenceName);                 // NOI18N
638
        Parameters.notNull("connectionFactoryName", connectionFactoryName); // NOI18N
639
        Parameters.notNull("destName", destName);                           // NOI18N
640
        Parameters.notNull("type", type);                                   // NOI18N
641
        
642
        ModuleConfiguration config = getModuleConfiguration();
643
        if (server == null || config == null) {
644
            return;
645
        }
646
        
647
        MessageDestinationConfiguration msgConfig = config.getLookup().lookup(MessageDestinationConfiguration.class);
648
        if (msgConfig != null) {
649
            msgConfig.bindMessageDestinationReferenceForEjb(ejbName, ejbType, referenceName, connectionFactoryName, destName, type);
650
        }
651
        
652
    }
394
    
653
    
395
    // DeploymentConfigurationProvider implementation -------------------------
654
    // DeploymentConfigurationProvider implementation -------------------------
396
    
655
    
(-)j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java (-5 / +17 lines)
Lines 13-36 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
19
20
package org.netbeans.modules.j2ee.deployment.devmodules.api;
20
package org.netbeans.modules.j2ee.deployment.devmodules.api;
21
21
22
import java.awt.event.WindowAdapter;
23
import java.awt.event.WindowEvent;
24
import java.util.ArrayList;
22
import java.util.ArrayList;
25
import java.util.Collection;
23
import java.util.Collection;
26
import java.util.Iterator;
24
import java.util.Iterator;
27
import java.util.List;
25
import java.util.List;
28
import java.util.Map;
29
import java.util.Set;
26
import java.util.Set;
30
import java.util.WeakHashMap;
31
import javax.enterprise.deploy.spi.Target;
27
import javax.enterprise.deploy.spi.Target;
32
import javax.enterprise.deploy.spi.status.ProgressObject;
28
import javax.enterprise.deploy.spi.status.ProgressObject;
33
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
29
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
30
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
34
import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener;
31
import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener;
35
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
32
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
36
import org.netbeans.modules.j2ee.deployment.impl.*;
33
import org.netbeans.modules.j2ee.deployment.impl.*;
Lines 119-124 Link Here
119
            }
116
            }
120
117
121
            jmp.deployDatasources();
118
            jmp.deployDatasources();
119
            
120
if (System.getProperties().getProperty("resource-api-redesign") != null) {
121
            deployMessageDestinations(jmp);
122
}
122
123
123
            modules = targetserver.deploy(progress, forceRedeploy);
124
            modules = targetserver.deploy(progress, forceRedeploy);
124
            // inform the plugin about the deploy action, even if there was
125
            // inform the plugin about the deploy action, even if there was
Lines 140-145 Link Here
140
            if (progress != null) {
141
            if (progress != null) {
141
                progress.finish();
142
                progress.finish();
142
            }
143
            }
144
        }
145
    }
146
    
147
    public void deployMessageDestinations(J2eeModuleProvider jmp) throws ConfigurationException {
148
        ServerInstance si = ServerRegistry.getInstance ().getServerInstance (jmp.getServerInstanceID ());
149
        if (si != null) {
150
            si.deployMessageDestinations(jmp.getConfigSupport().getMessageDestinations());
151
        }
152
        else {
153
            ErrorManager.getDefault().log(ErrorManager.WARNING, 
154
                    "The message destinations cannot be deployed because the server instance cannot be found.");
143
        }
155
        }
144
    }
156
    }
145
    
157
    
(-)j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java (-13 / +208 lines)
Lines 13-35 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
19
20
package org.netbeans.modules.j2ee.deployment.devmodules.spi;
20
package org.netbeans.modules.j2ee.deployment.devmodules.spi;
21
21
22
import java.beans.PropertyChangeListener;
23
import java.beans.PropertyChangeSupport;
24
import java.io.IOException;
25
import java.io.OutputStream;
22
import java.io.OutputStream;
26
import java.util.Collections;
23
import java.util.Collections;
27
import java.util.Iterator;
24
import java.util.Iterator;
28
import java.util.Map;
29
import java.util.Set;
25
import java.util.Set;
30
import javax.enterprise.deploy.spi.Target;
26
import javax.enterprise.deploy.spi.Target;
31
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
27
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
32
import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException;
33
import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping;
28
import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping;
34
import org.netbeans.modules.j2ee.deployment.common.api.ValidationException;
29
import org.netbeans.modules.j2ee.deployment.common.api.ValidationException;
35
import org.netbeans.modules.j2ee.deployment.config.*;
30
import org.netbeans.modules.j2ee.deployment.config.*;
Lines 38-44 Link Here
38
import org.netbeans.modules.j2ee.deployment.impl.Server;
33
import org.netbeans.modules.j2ee.deployment.impl.Server;
39
import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
34
import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
40
import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
35
import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
41
import org.netbeans.modules.j2ee.deployment.impl.ServerString;
42
import org.netbeans.modules.j2ee.deployment.impl.ServerTarget;
36
import org.netbeans.modules.j2ee.deployment.impl.ServerTarget;
43
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
37
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
44
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
38
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
Lines 49-59 Link Here
49
import org.netbeans.modules.j2ee.deployment.plugins.spi.VerifierSupport;
43
import org.netbeans.modules.j2ee.deployment.plugins.spi.VerifierSupport;
50
import org.openide.ErrorManager;
44
import org.openide.ErrorManager;
51
import org.openide.filesystems.FileObject;
45
import org.openide.filesystems.FileObject;
52
import org.openide.filesystems.FileUtil;
53
import org.openide.util.WeakListeners;
54
import java.io.File;
55
import java.util.ArrayList;
46
import java.util.ArrayList;
56
import java.util.List;
47
import java.util.List;
48
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
57
49
58
/** This object must be implemented by J2EE module support and an instance 
50
/** This object must be implemented by J2EE module support and an instance 
59
 * added into project lookup.
51
 * added into project lookup.
Lines 207-213 Link Here
207
        try {
199
        try {
208
            //btw, ds existence in a project is verified directly in the deployment configuration
200
            //btw, ds existence in a project is verified directly in the deployment configuration
209
            ds = getConfigSupport().createDatasource(jndiName, url, username, password, driver);
201
            ds = getConfigSupport().createDatasource(jndiName, url, username, password, driver);
210
        } catch (OperationUnsupportedException oue) {
202
        } catch (UnsupportedOperationException oue) {
211
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, oue);
203
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, oue);
212
        }
204
        }
213
        
205
        
Lines 339-352 Link Here
339
         * 
331
         * 
340
         * @return created data source
332
         * @return created data source
341
         * 
333
         * 
342
         * @throws OperationUnsupportedException if operation is not supported
334
         * @throws UnsupportedOperationException if operation is not supported
343
         * @throws DatasourceAlreadyExistsException if conflicting data source is found
335
         * @throws DatasourceAlreadyExistsException if conflicting data source is found
344
         * @throws ConfigurationException reports errors in creating the data source.
336
         * @throws ConfigurationException reports errors in creating the data source.
345
         *
337
         *
346
         * @since 1.15 
338
         * @since 1.15 
347
         */
339
         */
348
        public Datasource createDatasource(String jndiName, String  url, String username, String password, String driver)
340
        public Datasource createDatasource(String jndiName, String  url, String username, String password, String driver)
349
        throws OperationUnsupportedException, DatasourceAlreadyExistsException, ConfigurationException;
341
        throws UnsupportedOperationException, DatasourceAlreadyExistsException, ConfigurationException;
342
        
343
        /**
344
         * Binds the data source reference name with the corresponding data source which is
345
         * identified by the given JNDI name.
346
         * 
347
         * @param referenceName name used to identify the data source
348
         * @param jndiName JNDI name of the data source
349
         * 
350
         * @throws NullPointerException if any of parameters is null
351
         * @throws ConfigurationException if there is some problem with data source configuration
352
         * 
353
         * @since 1.25
354
         */
355
        public void bindDatasourceReference(String referenceName, String jndiName) throws ConfigurationException;
356
357
        /**
358
         * Binds the data source reference name with the corresponding data source which is
359
         * identified by the given JNDI name. The reference is used within the scope of the EJB.
360
         * 
361
         * @param ejbName EJB name
362
         * @param ejbType EJB type - the possible values are 
363
         *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION,
364
         *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY and
365
         *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN
366
         * @param referenceName name used to identify the data source
367
         * @param jndiName JNDI name of the data source
368
369
         * @throws NullPointerException if any of parameters is null
370
         * @throws ConfigurationException if there is some problem with data source configuration
371
         * @throws IllegalArgumentException if ejbType doesn't have one of allowed values
372
         * 
373
         * @since 1.25
374
         */
375
        public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, 
376
                String referenceName, String jndiName) throws ConfigurationException;
377
        
378
        /**
379
         * Finds JNDI name of data source which is mapped to the given reference name of a data source
380
         * 
381
         * @param referenceName reference name of data source
382
         * @return JNDI name which is mapped to the given JNDI name
383
         * 
384
         * @throws NullPointerException if reference name is null
385
         * @throws ConfigurationException if there is some problem with data source configuration
386
         * 
387
         * @since 1.25
388
         */
389
        public String findDatasourceJndiName(String referenceName) throws ConfigurationException;
390
        
391
        /**
392
         * Finds JNDI name of data source which is mapped to the given reference name in the scope of the EJB.
393
         * 
394
         * @param ejbName EJB name
395
         * @param referenceName reference name of data source
396
         * @return data source if it exists, null otherwise
397
         *
398
         * @throws NullPointerException if any of parameters is null
399
         * @throws ConfigurationException if there is some problem with data source configuration
400
         * 
401
         * @since 1.25
402
         */
403
        public String findDatasourceJndiNameForEjb(String ejbName, String referenceName) throws ConfigurationException;
404
        
405
        /**
406
         * Finds data source with the given JNDI name.
407
         * 
408
         * @param jndiName JNDI name of a data source
409
         * @param return data source if it exists, null otherwise
410
         *
411
         * @throws NullPointerException if JNDI name is null
412
         * @throws ConfigurationException if there is some problem with data source configuration
413
         * 
414
         * @since 1.25
415
         */
416
        public Datasource findDatasource(String jndiName) throws ConfigurationException;
417
418
        /**
419
         * Retrieves message destinations stored in the module.
420
         * 
421
         * @return set of message destinations
422
         * 
423
         * @throws ConfigurationException if there is some problem with message destination configuration
424
         * 
425
         * @since 1.25
426
         */
427
        public Set<MessageDestination> getMessageDestinations() throws ConfigurationException;
428
429
        /**
430
         * Retrieves message destinations configured on the target server instance.
431
         *
432
         * @return set of message destinations
433
         * 
434
         * @throws ConfigurationException if there is some problem with message destination configuration
435
         * 
436
         * @since 1.25 
437
         */
438
        public Set<MessageDestination> getServerMessageDestinations() throws ConfigurationException;
439
        
440
        /**
441
         * Tests whether a message destination creation is supported.
442
         *
443
         * @return true if message destination creation is supported, false otherwise.
444
         *
445
         * @since 1.25
446
         */
447
        public boolean supportsCreateMessageDestination();
448
449
        /**
450
         * Creates and saves a message destination in the module if it does not exist in the module yet.
451
         * Message destinations are considered to be equal if their JNDI names are equal.
452
         *
453
         * @param name name of the message destination
454
         * @param type message destination type
455
         * @return created message destination
456
         * 
457
         * @throws NullPointerException if any of parameters is null
458
         * @throws UnsupportedOperationException if this opearation is not supported
459
         * @throws ConfigurationException if there is some problem with message destination configuration
460
         *
461
         * @since 1.25 
462
         */
463
        public MessageDestination createMessageDestination(String name, MessageDestination.Type type) 
464
        throws UnsupportedOperationException, ConfigurationException;
465
        
466
        /**
467
         * Binds the message destination name with message-driven bean.
468
         * 
469
         * @param mdbName MDB name
470
         * @param name name of the message destination
471
         * @param type message destination type
472
         * 
473
         * @throws NullPointerException if any of parameters is null
474
         * @throws ConfigurationException if there is some problem with message destination configuration
475
         * 
476
         * @since 1.25
477
         */
478
        public void bindMdbToMessageDestination(String mdbName, String name, MessageDestination.Type type) throws ConfigurationException;
479
480
        /**
481
         * Finds name of message destination which the given MDB listens to
482
         * 
483
         * @param mdbName MDB name
484
         * @return message destination name
485
         * 
486
         * @throws NullPointerException if MDB name is null
487
         * @throws ConfigurationException if there is some problem with message destination configuration
488
         * 
489
         * @since 1.25
490
         */
491
        public String findMessageDestinationName(String mdbName) throws ConfigurationException;
492
493
        /**
494
         * Finds message destination with the given name.
495
         * 
496
         * @param name message destination name
497
         * @param return message destination if it exists, null otherwise
498
         *
499
         * @throws NullPointerException if name is null
500
         * @throws ConfigurationException if there is some problem with message destination configuration
501
         * 
502
         * @since 1.25
503
         */
504
        public MessageDestination findMessageDestination(String name) throws ConfigurationException;
505
506
        /**
507
         * Binds the message destination reference name with the corresponding message destination which is
508
         * identified by the given name.
509
         * 
510
         * @param referenceName reference name used to identify the message destination
511
         * @param connectionFactoryName connection factory name
512
         * @param destName name of the message destination
513
         * @param type message destination type
514
         * 
515
         * @throws NullPointerException if any of parameters is null
516
         * @throws ConfigurationException if there is some problem with message destination configuration
517
         * 
518
         * @since 1.25
519
         */
520
        public void bindMessageDestinationReference(String referenceName, String connectionFactoryName, 
521
                String destName, MessageDestination.Type type) throws ConfigurationException;
522
523
        /**
524
         * Binds the message destination reference name with the corresponding message destination which is
525
         * identified by the given name. The reference is used within the EJB scope.
526
         * 
527
         * @param ejbName EJB name
528
         * @param ejbType EJB type - the possible values are 
529
         *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION,
530
         *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY and
531
         *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN
532
         * @param referenceName reference name used to identify the message destination
533
         * @param connectionFactoryName connection factory name
534
         * @param destName name of the message destination
535
         * @param type message destination type
536
         * 
537
         * @throws NullPointerException if any of parameters is null
538
         * @throws ConfigurationException if there is some problem with message destination configuration
539
         * 
540
         * @since 1.25
541
         */
542
        public void bindMessageDestinationReferenceForEjb(String ejbName, String ejbType,
543
                String referenceName, String connectionFactoryName,
544
                String destName, MessageDestination.Type type) throws ConfigurationException;
350
    }
545
    }
351
546
352
    /**
547
    /**
(-)j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java (-1 / +65 lines)
Lines 13-19 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
19
Lines 39-44 Link Here
39
import org.openide.filesystems.*;
39
import org.openide.filesystems.*;
40
import java.util.*;
40
import java.util.*;
41
import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
41
import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
42
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
42
import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
43
import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
43
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
44
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
44
import org.netbeans.modules.j2ee.deployment.impl.ui.ProgressUI;
45
import org.netbeans.modules.j2ee.deployment.impl.ui.ProgressUI;
Lines 53-58 Link Here
53
import org.netbeans.modules.j2ee.deployment.plugins.spi.FindJSPServlet;
54
import org.netbeans.modules.j2ee.deployment.plugins.spi.FindJSPServlet;
54
import org.netbeans.modules.j2ee.deployment.plugins.spi.IncrementalDeployment;
55
import org.netbeans.modules.j2ee.deployment.plugins.spi.IncrementalDeployment;
55
import org.netbeans.modules.j2ee.deployment.plugins.spi.J2eePlatformFactory;
56
import org.netbeans.modules.j2ee.deployment.plugins.spi.J2eePlatformFactory;
57
import org.netbeans.modules.j2ee.deployment.plugins.spi.MessageDestinationDeployment;
56
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
58
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
57
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerSupport;
59
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerSupport;
58
import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler;
60
import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler;
Lines 61-66 Link Here
61
import org.openide.util.NbBundle;
63
import org.openide.util.NbBundle;
62
import org.openide.NotifyDescriptor;
64
import org.openide.NotifyDescriptor;
63
import org.openide.DialogDisplayer;
65
import org.openide.DialogDisplayer;
66
import org.openide.util.Parameters;
64
import org.openide.util.RequestProcessor;
67
import org.openide.util.RequestProcessor;
65
import org.openide.windows.InputOutput;
68
import org.openide.windows.InputOutput;
66
69
Lines 104-109 Link Here
104
    private FindJSPServlet findJSPServlet;
107
    private FindJSPServlet findJSPServlet;
105
    private DatasourceManager dsMgr;
108
    private DatasourceManager dsMgr;
106
    private DatasourceManager ddsMgr;
109
    private DatasourceManager ddsMgr;
110
    private MessageDestinationDeployment msgDestDeploymentConnected;
111
    private MessageDestinationDeployment msgDestDeploymentDisconnected;
107
    private final Set targetsStartedByIde = new HashSet(); // valued by target name
112
    private final Set targetsStartedByIde = new HashSet(); // valued by target name
108
    private Map targets; // keyed by target name, valued by ServerTarget
113
    private Map targets; // keyed by target name, valued by ServerTarget
109
    private boolean managerStartedByIde = false;
114
    private boolean managerStartedByIde = false;
Lines 565-570 Link Here
565
570
566
        if (dsMgr != null) 
571
        if (dsMgr != null) 
567
            dsMgr.deployDatasources(datasources);
572
            dsMgr.deployDatasources(datasources);
573
    }
574
    
575
    private synchronized MessageDestinationDeployment getMessageDestinationDeploymentConnected() {
576
        if (msgDestDeploymentConnected == null) {
577
            msgDestDeploymentConnected = server.getOptionalFactory().
578
                    getMessageDestinationDeployment(getDeploymentManager());
579
        }
580
581
        return msgDestDeploymentConnected;
582
    }
583
    
584
    private MessageDestinationDeployment getMessageDestinationDeploymentDisconnected() {
585
        DeploymentManager dm = null;
586
        try {
587
            dm = getDisconnectedDeploymentManager();
588
        }  catch (DeploymentManagerCreationException dmce) {
589
            throw new RuntimeException(dmce);
590
        }
591
        synchronized (this) {
592
            if (msgDestDeploymentDisconnected == null) {
593
                msgDestDeploymentDisconnected = server.getOptionalFactory().getMessageDestinationDeployment(dm);
594
            }
595
            return msgDestDeploymentDisconnected;
596
        }
597
    }
598
    
599
    /**
600
     * Retrieves message destinations configured on the target server instance.
601
     *
602
     * @return set of message destinations
603
     * 
604
     * @throws ConfigurationException if there is some problem with message destination configuration
605
     */
606
    public Set<MessageDestination> getMessageDestinations() throws ConfigurationException {
607
        
608
        MessageDestinationDeployment destDepl = getMessageDestinationDeploymentDisconnected();
609
        if (destDepl != null) {
610
            return destDepl.getMessageDestinations();
611
        }
612
        
613
        return Collections.<MessageDestination>emptySet();
614
    }
615
    
616
    /**
617
     * Deploys message destinations saved in the module.
618
     *
619
     * @param destinations set of message destinations
620
     * 
621
     * @throws NullPointerException if destinations parameter is null
622
     * @throws ConfigurationException if there is some problem with message destination configuration
623
     */
624
    public void deployMessageDestinations(Set<MessageDestination> destinations) throws ConfigurationException {
625
    
626
        Parameters.notNull("destinations", destinations);
627
        
628
        MessageDestinationDeployment destDepl = getMessageDestinationDeploymentConnected();
629
        if (destDepl != null) {
630
            destDepl.deployMessageDestinations(destinations);
631
        }
568
    }
632
    }
569
    
633
    
570
    //---------- State API's:  running, debuggable, startedByIDE -----------
634
    //---------- State API's:  running, debuggable, startedByIDE -----------
(-)j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/MessageDestinationDeployment.java (+53 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.j2ee.deployment.plugins.spi;
21
22
import java.util.Set;
23
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
24
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
25
26
/**
27
 * MessageDestinationDeployment is responsible for retrieving message destinations
28
 * configured on the server and for message destination deployment.
29
 *
30
 * @author Libor Kotouc
31
 *
32
 * @since 1.25
33
 */
34
public interface MessageDestinationDeployment {
35
    
36
    /**
37
     * Retrieves message destinations configured on the target server instance.
38
     *
39
     * @return set of message destinations
40
     * 
41
     * @throws ConfigurationException if there is some problem with message destination configuration
42
     */
43
    Set<MessageDestination> getMessageDestinations() throws ConfigurationException;
44
45
    /**
46
     * Deploys message destinations saved in the module.
47
     *
48
     * @param destinations set of message destinations
49
     * 
50
     * @exception ConfigurationException if there is some problem with message destination configuration
51
     */
52
    void deployMessageDestinations(Set<MessageDestination> destinations) throws ConfigurationException;
53
}
(-)j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java (-3 / +17 lines)
Lines 13-19 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
19
Lines 21-28 Link Here
21
package org.netbeans.modules.j2ee.deployment.plugins.spi;
21
package org.netbeans.modules.j2ee.deployment.plugins.spi;
22
22
23
import javax.enterprise.deploy.spi.DeploymentManager;
23
import javax.enterprise.deploy.spi.DeploymentManager;
24
import org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer;
25
import org.netbeans.modules.j2ee.deployment.plugins.spi.TargetModuleIDResolver;
26
import org.openide.WizardDescriptor;
24
import org.openide.WizardDescriptor;
27
25
28
/**
26
/**
Lines 107-110 Link Here
107
    public JDBCDriverDeployer getJDBCDriverDeployer(DeploymentManager dm) {
105
    public JDBCDriverDeployer getJDBCDriverDeployer(DeploymentManager dm) {
108
        return null;
106
        return null;
109
    }
107
    }
108
109
    /**
110
     * Creates a <code>MessageDestinationDeployment</code> for the given deployment manager
111
     * or <code>null</code> if message destination deployment is not supported
112
     *
113
     * @param dm the deployment manager
114
     *
115
     * @return a message destination deployment or <code>null</code> 
116
     *          if message destination deployment is not supported
117
     *
118
     * @since 1.25
119
     */
120
    public MessageDestinationDeployment getMessageDestinationDeployment(DeploymentManager dm) {
121
        return null;
122
    }
123
    
110
}
124
}
(-)j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/DatasourceConfiguration.java (+56 lines)
Lines 71-74 Link Here
71
     */
71
     */
72
    Datasource createDatasource(String jndiName, String  url, String username, String password, String driver) 
72
    Datasource createDatasource(String jndiName, String  url, String username, String password, String driver) 
73
    throws UnsupportedOperationException, ConfigurationException, DatasourceAlreadyExistsException;
73
    throws UnsupportedOperationException, ConfigurationException, DatasourceAlreadyExistsException;
74
75
    /**
76
     * Binds the data source reference name with the corresponding data source which is
77
     * identified the given JNDI name.
78
     * 
79
     * @param referenceName name used to identify the data source
80
     * @param jndiName JNDI name of the data source
81
     * @throws ConfigurationException if there is some problem with data source configuration
82
     * 
83
     * @since 1.25
84
     */
85
    public void bindDatasourceReference(String referenceName, String jndiName) throws ConfigurationException;
86
87
    /**
88
     * Binds the data source reference name with the corresponding data source which is
89
     * identified the given JNDI name. The reference is used within the scope of the EJB.
90
     * 
91
     * @param ejbName EJB name
92
     * @param ejbType EJB type - the possible values are 
93
     *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION,
94
     *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY and
95
     *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN
96
     * @param referenceName name used to identify the data source
97
     * @param jndiName JNDI name of the data source
98
     *
99
     * @throws ConfigurationException if there is some problem with data source configuration
100
     * 
101
     * @since 1.25
102
     */
103
    public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, 
104
            String referenceName, String jndiName) throws ConfigurationException;
105
106
    /**
107
     * Finds JNDI name of the data source which is mapped to the given reference name.
108
     * 
109
     * @referenceName reference name
110
     * @return JNDI name of the data source if the mapping exists, null otherwise
111
     *
112
     * @throws ConfigurationException if there is some problem with data source configuration
113
     * 
114
     * @since 1.25
115
     */
116
    public String findDatasourceJndiName(String referenceName) throws ConfigurationException;
117
    
118
    /**
119
     * Finds JNDI name of the data source which is mapped to the given reference name in the scope the EJB.
120
     * 
121
     * @param ejbName EJB name
122
     * @param referenceName reference name
123
     * @return JNDI name of the data source if the mapping exists, null otherwise
124
     *
125
     * @throws ConfigurationException if there is some problem with data source configuration
126
     * 
127
     * @since 1.25
128
     */
129
    public String findDatasourceJndiNameForEjb(String ejbName, String referenceName) throws ConfigurationException;
74
}
130
}
(-)j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/MessageDestinationConfiguration.java (+137 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.j2ee.deployment.plugins.spi.config;
21
22
import java.util.List;
23
import java.util.Set;
24
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
25
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
26
27
/**
28
 * Configuration useful for managing module message destinations.
29
 * <p>
30
 * Implementation of this interface should be registered in the {@link ModuleConfiguration}
31
 * lookup.
32
 *
33
 * @author Libor Kotouc
34
 */
35
public interface MessageDestinationConfiguration {
36
    
37
    /**
38
     * Retrieves message destinations stored in the module.
39
     * 
40
     * @return set of message destinations
41
     * 
42
     * @throws ConfigurationException if there is some problem with message destination configuration
43
     * 
44
     * @since 1.25
45
     */
46
    public Set<MessageDestination> getMessageDestinations() throws ConfigurationException;
47
    
48
    /**
49
     * Tests whether a message destination creation is supported.
50
     *
51
     * @return true if message destination creation is supported, false otherwise.
52
     *
53
     * @since 1.25
54
     */
55
    public boolean supportsCreateMessageDestination();
56
            
57
    /**
58
     * Creates and saves a message destination in the module if it does not exist in the module yet.
59
     * Message destinations are considered to be equal if their JNDI names are equal.
60
     *
61
     * @param name name of the message destination
62
     * @param type message destination type; the value is of 
63
     * org.netbeans.modules.j2ee.deployment.common.api.MessageDestination.Type type
64
     * @return created message destination
65
     * 
66
     * @throws UnsupportedOperationException if this opearation is not supported
67
     * @throws ConfigurationException if there is some problem with message destination configuration
68
     *
69
     * @since 1.25 
70
     */
71
    public MessageDestination createMessageDestination(String name, MessageDestination.Type type) 
72
    throws UnsupportedOperationException, ConfigurationException;
73
    
74
    /**
75
     * Binds the message destination name with message-driven bean.
76
     * 
77
     * @param mdbName MDB name
78
     * @param name name of the message destination
79
     * @param type message destination type; the value is of 
80
     * 
81
     * @throws ConfigurationException if there is some problem with message destination configuration
82
     * 
83
     * @since 1.25
84
     */
85
    public void bindMdbToMessageDestination(String mdbName, String name, MessageDestination.Type type) throws ConfigurationException;
86
    
87
    /**
88
     * Finds name of message destination which the given MDB listens to
89
     * 
90
     * @param mdbName MDB name
91
     * @return message destination name
92
     * 
93
     * @throws ConfigurationException if there is some problem with message destination configuration
94
     * 
95
     * @since 1.25
96
     */
97
    public String findMessageDestinationName(String mdbName) throws ConfigurationException;
98
99
    /**
100
     * Binds the message destination reference name with the corresponding message destination which is
101
     * identified by the given name.
102
     * 
103
     * @param referenceName reference name used to identify the message destination
104
     * @param connectionFactoryName connection factory name
105
     * @param destName name of the message destination
106
     * @param type message destination type
107
     * 
108
     * @throws ConfigurationException if there is some problem with message destination configuration
109
     * 
110
     * @since 1.25
111
     */
112
    public void bindMessageDestinationReference(String referenceName, String connectionFactoryName, 
113
            String destName, MessageDestination.Type type) throws ConfigurationException;
114
115
    /**
116
     * Binds the message destination reference name with the corresponding message destination which is
117
     * identified by the given name. The reference is used within the EJB scope.
118
     * 
119
     * @param ejbName EJB name
120
     * @param ejbType EJB type - the possible values are 
121
     *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION,
122
     *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY and
123
     *        org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN
124
     * @param referenceName reference name used to identify the message destination
125
     * @param connectionFactoryName connection factory name
126
     * @param destName name of the message destination
127
     * @param type message destination type
128
     * 
129
     * @throws ConfigurationException if there is some problem with message destination configuration
130
     * 
131
     * @since 1.25
132
     */
133
    public void bindMessageDestinationReferenceForEjb(String ejbName, String ejbType,
134
            String referenceName, String connectionFactoryName,
135
            String destName, MessageDestination.Type type) throws ConfigurationException;
136
    
137
}
(-)j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/config/ModuleConfiguration.java (-1 / +2 lines)
Lines 39-45 Link Here
39
     * implementations of all the supported configurations.
39
     * implementations of all the supported configurations.
40
     * <p>
40
     * <p>
41
     * The configuration are:  {@link ContextRootConfiguration},  {@link DatasourceConfiguration}, 
41
     * The configuration are:  {@link ContextRootConfiguration},  {@link DatasourceConfiguration}, 
42
     * {@link MappingConfiguration}, {@link EjbResourceConfiguration}, {@link DeploymentPlanConfiguration}
42
     * {@link MappingConfiguration}, {@link EjbResourceConfiguration}, {@link DeploymentPlanConfiguration},
43
     * {@link MessageDestinationConfiguration}
43
     * <p>
44
     * <p>
44
     * Implementators are advised to use {@link org.openide.util.lookup.Lookups#fixed}
45
     * Implementators are advised to use {@link org.openide.util.lookup.Lookups#fixed}
45
     * to implement this method.
46
     * to implement this method.
(-)serverplugins/jboss4/build.xml (+8 lines)
Lines 67-72 Link Here
67
	  removeUnreferencedNodes="true"
67
	  removeUnreferencedNodes="true"
68
          docroot="datasources"
68
          docroot="datasources"
69
	  rootDir="src"/>
69
	  rootDir="src"/>
70
	<schema2beans schema="${jb_dir}/resources/jboss-service_4_0.dtd"
71
	  package="org.netbeans.modules.j2ee.jboss4.config.gen"
72
	  schemaType="dtd"
73
	  validate="true"
74
	  attrProp="true"
75
	  removeUnreferencedNodes="true"
76
          docroot="server"
77
	  rootDir="src"/>
70
	<schema2beans schema="${jb_dir}/resources/jboss-client_4_0.dtd"
78
	<schema2beans schema="${jb_dir}/resources/jboss-client_4_0.dtd"
71
	  package="org.netbeans.modules.j2ee.jboss4.config.gen"
79
	  package="org.netbeans.modules.j2ee.jboss4.config.gen"
72
	  schemaType="dtd"
80
	  schemaType="dtd"
(-)serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/Bundle.properties (+2 lines)
Lines 60-62 Link Here
60
60
61
ERR_CannotReadDSdotXml=Cannot read jboss-ds.xml file on the server
61
ERR_CannotReadDSdotXml=Cannot read jboss-ds.xml file on the server
62
ERR_CannotCreateDSdotXml=Cannot create jboss-ds.xml file on the server
62
ERR_CannotCreateDSdotXml=Cannot create jboss-ds.xml file on the server
63
64
MSG_NoPrefix=Message destination JNDI name {0} doesn't start with either 'queue/' or 'topic/' prefix
(-)serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/CarDeploymentConfiguration.java (-2 / +6 lines)
Lines 13-19 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
19
Lines 111-117 Link Here
111
                } else {
111
                } else {
112
                    // create jboss-web.xml if it does not exist yet
112
                    // create jboss-web.xml if it does not exist yet
113
                    jbossClient = generateJbossClient();
113
                    jbossClient = generateJbossClient();
114
                    writefile(jbossClientFile, jbossClient);
114
                    writeFile(jbossClientFile, jbossClient);
115
                }
115
                }
116
            } catch (ConfigurationException ce) {
116
            } catch (ConfigurationException ce) {
117
                ErrorManager.getDefault().notify(ce);
117
                ErrorManager.getDefault().notify(ce);
Lines 419-424 Link Here
419
419
420
    public boolean supportsCreateDatasource() {
420
    public boolean supportsCreateDatasource() {
421
        return true;
421
        return true;
422
    }
423
424
    public boolean supportsCreateMessageDestination() {
425
        return false;
422
    }
426
    }
423
    
427
    
424
    // private helper interface -----------------------------------------------
428
    // private helper interface -----------------------------------------------
(-)serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/EarDeploymentConfiguration.java (-2 / +7 lines)
Lines 13-19 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
19
Lines 91-97 Link Here
91
                } else {
91
                } else {
92
                    // create jboss-app.xml if it does not exist yet
92
                    // create jboss-app.xml if it does not exist yet
93
                    jbossApp = genereatejbossApp();
93
                    jbossApp = genereatejbossApp();
94
                    writefile(jbossAppFile, jbossApp);
94
                    writeFile(jbossAppFile, jbossApp);
95
                }
95
                }
96
            } catch (ConfigurationException ce) {
96
            } catch (ConfigurationException ce) {
97
                ErrorManager.getDefault().notify(ce);
97
                ErrorManager.getDefault().notify(ce);
Lines 126-129 Link Here
126
    public boolean supportsCreateDatasource() {
126
    public boolean supportsCreateDatasource() {
127
        return false;
127
        return false;
128
    }
128
    }
129
    
130
    public boolean supportsCreateMessageDestination() {
131
        return false;
132
    }
133
    
129
}
134
}
(-)serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/EjbDeploymentConfiguration.java (-26 / +184 lines)
Lines 13-19 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
19
Lines 27-32 Link Here
27
import java.io.OutputStream;
27
import java.io.OutputStream;
28
import java.util.HashMap;
28
import java.util.HashMap;
29
import java.util.HashSet;
29
import java.util.HashSet;
30
import java.util.LinkedList;
31
import java.util.List;
30
import java.util.Map;
32
import java.util.Map;
31
import java.util.Set;
33
import java.util.Set;
32
import javax.enterprise.deploy.model.DDBean;
34
import javax.enterprise.deploy.model.DDBean;
Lines 35-47 Link Here
35
import javax.swing.text.StyledDocument;
37
import javax.swing.text.StyledDocument;
36
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
38
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
37
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
39
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
40
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
38
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
41
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
39
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DatasourceConfiguration;
42
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DatasourceConfiguration;
40
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DeploymentPlanConfiguration;
43
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DeploymentPlanConfiguration;
41
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfiguration;
44
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfiguration;
42
import org.netbeans.modules.j2ee.jboss4.config.gen.EnterpriseBeans;
45
import org.netbeans.modules.j2ee.jboss4.config.gen.EnterpriseBeans;
46
import org.netbeans.modules.j2ee.jboss4.config.gen.Entity;
43
import org.netbeans.modules.j2ee.jboss4.config.gen.Jboss;
47
import org.netbeans.modules.j2ee.jboss4.config.gen.Jboss;
44
import org.netbeans.modules.j2ee.jboss4.config.gen.MessageDriven;
48
import org.netbeans.modules.j2ee.jboss4.config.gen.MessageDriven;
49
import org.netbeans.modules.j2ee.jboss4.config.gen.ResourceRef;
50
import org.netbeans.modules.j2ee.jboss4.config.gen.Session;
45
import org.openide.DialogDisplayer;
51
import org.openide.DialogDisplayer;
46
import org.openide.ErrorManager;
52
import org.openide.ErrorManager;
47
import org.openide.NotifyDescriptor;
53
import org.openide.NotifyDescriptor;
Lines 130-136 Link Here
130
    public boolean supportsCreateDatasource() {
136
    public boolean supportsCreateDatasource() {
131
        return true;
137
        return true;
132
    }
138
    }
133
        
139
    
140
    public boolean supportsCreateMessageDestination() {
141
        return true;
142
    }
143
    
134
//        //listen on the resource-ref element
144
//        //listen on the resource-ref element
135
//        deplObj.getDDBeanRoot().addXpathListener(SESSION_RESOURCE_REF, this);
145
//        deplObj.getDDBeanRoot().addXpathListener(SESSION_RESOURCE_REF, this);
136
//        deplObj.getDDBeanRoot().addXpathListener(ENTITY_RESOURCE_REF, this);
146
//        deplObj.getDDBeanRoot().addXpathListener(ENTITY_RESOURCE_REF, this);
Lines 165-171 Link Here
165
                } else {
175
                } else {
166
                    // create jboss.xml if it does not exist yet
176
                    // create jboss.xml if it does not exist yet
167
                    jboss = generateJboss();
177
                    jboss = generateJboss();
168
                    writefile(jbossFile, jboss);
178
                    writeFile(jbossFile, jboss);
169
                }
179
                }
170
            } catch (ConfigurationException ce) {
180
            } catch (ConfigurationException ce) {
171
                ErrorManager.getDefault().notify(ce);
181
                ErrorManager.getDefault().notify(ce);
Lines 237-243 Link Here
237
//                        Set beanNames = null;
247
//                        Set beanNames = null;
238
//                        if (desc.length > 0  && "javax.sql.DataSource".equals(type[0])) { // NOI18N
248
//                        if (desc.length > 0  && "javax.sql.DataSource".equals(type[0])) { // NOI18N
239
//                            beanNames = getRelevantBeansDataRef(desc[0], name[0], eventDDBean.getRoot(), beanType);
249
//                            beanNames = getRelevantBeansDataRef(desc[0], name[0], eventDDBean.getRoot(), beanType);
240
//                            addResReference(desc[0], name[0], beanNames, beanType);
250
//                            String jndiName = JBDeploymentConfiguration.JBOSS4_DATASOURCE_JNDI_PREFIX + resRefName;
251
//                            addResReference(jndiName, name[0], beanNames, beanType);
241
//                        }
252
//                        }
242
//                        else
253
//                        else
243
//                        if ("javax.mail.Session".equals(type[0])) { // NOI18N
254
//                        if ("javax.mail.Session".equals(type[0])) { // NOI18N
Lines 724-764 Link Here
724
        
735
        
725
        return beanMap;
736
        return beanMap;
726
    }
737
    }
738
739
    public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, 
740
            String referenceName, String jndiName) throws ConfigurationException {
741
        
742
        Set beanNames = new HashSet();
743
        beanNames.add(ejbName);
744
        if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION.equals(ejbType)) {
745
            addResReference(jndiName, referenceName, beanNames, BEAN_TYPE.SESSION);
746
        }
747
        else
748
        if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY.equals(ejbType)) {
749
            addResReference(jndiName, referenceName, beanNames, BEAN_TYPE.ENTITY);
750
        }
751
        else
752
        if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN.equals(ejbType)) {
753
            addMsgDrvResReference(jndiName, referenceName, ejbName);
754
        }
755
756
    }
757
    
758
    public String findDatasourceJndiNameForEjb(String ejbName, String referenceName) throws ConfigurationException {
759
760
        EnterpriseBeans beans = getJboss().getEnterpriseBeans();
761
        if (beans == null) {
762
            return null;
763
        }
764
        
765
        Session[] sessions = beans.getSession();
766
        for (Session session : sessions) {
767
            if (ejbName.equals(session.getEjbName())) {
768
                ResourceRef[] resourceRefs = session.getResourceRef();
769
                for (ResourceRef resourceRef : resourceRefs) {
770
                    String rrn = resourceRef.getResRefName();
771
                    if (referenceName.equals(rrn)) {
772
                        return resourceRef.getJndiName();
773
                    }
774
                }
775
                return null;
776
            }
777
        }
778
779
        Entity[] entities = beans.getEntity();
780
        for (Entity entity : entities) {
781
            if (ejbName.equals(entity.getEjbName())) {
782
                ResourceRef[] resourceRefs = entity.getResourceRef();
783
                for (ResourceRef resourceRef : resourceRefs) {
784
                    String rrn = resourceRef.getResRefName();
785
                    if (referenceName.equals(rrn)) {
786
                        return resourceRef.getJndiName();
787
                    }
788
                }
789
                return null;
790
            }
791
        }
792
793
        MessageDriven[] mdbs = beans.getMessageDriven();
794
        for (MessageDriven mdb : mdbs) {
795
            if (ejbName.equals(mdb.getEjbName())) {
796
                ResourceRef[] resourceRefs = mdb.getResourceRef();
797
                for (ResourceRef resourceRef : resourceRefs) {
798
                    String rrn = resourceRef.getResRefName();
799
                    if (referenceName.equals(rrn)) {
800
                        return resourceRef.getJndiName();
801
                    }
802
                }
803
                return null;
804
            }
805
        }
806
        
807
        return null;
808
    }    
809
    
727
    
810
    
728
    /**
811
    /**
729
     * Add a new data source reference to the beans of the given type without it.
812
     * Add a new data source reference to the beans of the given type without it.
730
     * 
813
     * 
731
     * @param desc data source description
814
     * @param jndiName JNDI name of the resource
732
     * @param resRefName data source reference name
815
     * @param resRefName data source reference name
733
     * @param beanNames the beans (ejb-name value) which might need to add data source reference specified by resRefName
816
     * @param beanNames the beans (ejb-name value) which might need to add data source reference specified by resRefName
734
     * @param beanType type of bean to add data source reference to
817
     * @param beanType type of bean to add data source reference to
735
     */
818
     */
736
    private void addResReference(String desc, final String resRefName, final Set beanNames, final BEAN_TYPE beanType) 
819
    private void addResReference(final String jndiName, final String resRefName, final Set beanNames, final BEAN_TYPE beanType) 
737
    throws ConfigurationException 
820
    throws ConfigurationException 
738
    {
821
    {
739
        modifyJboss(new JbossModifier() {
822
        modifyJboss(new JbossModifier() {
740
           public void modify(Jboss modifiedJboss) {
823
           public void modify(Jboss modifiedJboss) {
741
               String jndiName = JBDeploymentConfiguration.JBOSS4_DATASOURCE_JNDI_PREFIX + resRefName;
742
               JbossDataSourceRefModifier.modify(modifiedJboss, resRefName, beanNames, beanType, jndiName);
824
               JbossDataSourceRefModifier.modify(modifiedJboss, resRefName, beanNames, beanType, jndiName);
743
           }
825
           }
744
        });
826
        });
745
    }
827
    }
746
828
747
    /**
829
    /**
748
     * Add a new resource reference to the message-driven beans without it.
830
     * Add a new resource reference to the message-driven bean.
749
     * 
831
     * 
750
     * @param desc data source description
832
     * @param jndiName JNDI name of the resource
751
     * @param resRefName resource reference name
833
     * @param resRefName resource reference name
752
     * @param beans the bean names (ejb-name) mapped to the message destinations (message-destination-link)
834
     * @param mdbName the MDB (ejb-name) which might need to add resource reference specified by resRefName
753
     * which might need to add resource reference specified by resRefName
835
     * which might need to add resource reference specified by resRefName
754
     */
836
     */
755
    private void addMsgDrvResReference(String desc, final String resRefName, final Map beans) 
837
    private void addMsgDrvResReference(final String jndiName, final String resRefName, final String mdbName) 
756
    throws ConfigurationException 
838
    throws ConfigurationException 
757
    {
839
    {
758
        modifyJboss(new JbossModifier() {
840
        modifyJboss(new JbossModifier() {
759
           public void modify(Jboss modifiedJboss) {
841
           public void modify(Jboss modifiedJboss) {
760
               String jndiName = JBDeploymentConfiguration.JBOSS4_DATASOURCE_JNDI_PREFIX + resRefName;
842
               JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, mdbName, jndiName);
761
               JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName);
762
           }
843
           }
763
        });
844
        });
764
    }
845
    }
Lines 833-845 Link Here
833
        });
914
        });
834
    }
915
    }
835
916
917
    public void bindMdbToMessageDestination(String mdbName, String name, MessageDestination.Type type) throws ConfigurationException {
918
        addMDB(mdbName, name, type);
919
    }
920
    
921
    public String findMessageDestinationName(String mdbName) throws ConfigurationException {
922
923
        EnterpriseBeans beans = getJboss().getEnterpriseBeans();
924
        if (beans == null) {
925
            return null;
926
        }
927
        
928
        MessageDriven[] mdbs = beans.getMessageDriven();
929
        for (MessageDriven mdb : mdbs) {
930
            if (mdbName.equals(mdb.getEjbName())) {
931
                String destJndiName = mdb.getDestinationJndiName();
932
                if (destJndiName != null) {
933
                    if (destJndiName.startsWith("queue/") || destJndiName.startsWith("topic/")) {
934
                        return destJndiName.substring(6); // "queue/".length() == "topic/".length() == 6
935
                    }
936
                    else {
937
                        ErrorManager.getDefault().log(
938
                                ErrorManager.INFORMATIONAL, 
939
                                NbBundle.getMessage(EjbDeploymentConfiguration.class, "MSG_NoPrefix", destJndiName));
940
                    }
941
                }
942
                return null;
943
            }
944
        }
945
        
946
        return null;
947
    }
948
836
    /**
949
    /**
837
     * Add MDB record.
950
     * Add MDB record.
838
     * 
951
     * 
839
     * @param name MDB name (ejb-name)
952
     * @param name MDB name (ejb-name)
840
     * @param dest MDB destination (message-destination-link)
953
     * @param dest MDB destination (message-destination-link)
841
     */
954
     */
842
    private void addMDB(final String name, final String dest) throws ConfigurationException {
955
    private void addMDB(final String name, final String destName, final MessageDestination.Type destType) 
956
    throws ConfigurationException {
957
        
843
        modifyJboss(new JbossModifier() {
958
        modifyJboss(new JbossModifier() {
844
            public void modify(Jboss modifiedJboss) {
959
            public void modify(Jboss modifiedJboss) {
845
960
Lines 862-868 Link Here
862
                //if it doesn't exist yet, create a new one
977
                //if it doesn't exist yet, create a new one
863
                MessageDriven mdb = new MessageDriven();
978
                MessageDriven mdb = new MessageDriven();
864
                mdb.setEjbName(name);
979
                mdb.setEjbName(name);
865
                mdb.setDestinationJndiName(dest); // NOI18N
980
                if (MessageDestination.Type.QUEUE.equals(destType)) {
981
                    mdb.setDestinationJndiName("queue/" + destName); // NOI18N
982
                }
983
                else
984
                if (MessageDestination.Type.TOPIC.equals(destType)) {
985
                    mdb.setDestinationJndiName("topic/" + destName); // NOI18N
986
                }
866
                eb.addMessageDriven(mdb);
987
                eb.addMessageDriven(mdb);
867
            }
988
            }
868
        });
989
        });
Lines 889-922 Link Here
889
    /**
1010
    /**
890
     * Add a new connection factory reference to the message-driven beans without it.
1011
     * Add a new connection factory reference to the message-driven beans without it.
891
     * 
1012
     * 
892
     * @param resRefName connection factory reference name
1013
     * @param connectionFactoryName connection factory reference name
893
     * @param beans the bean names (ejb-name) mapped to the message destinations (message-destination-link)
1014
     * @param mdbName the MDB (ejb-name) which might need to add connection factory reference specified by resRefName
894
     * which might need to add connection factory reference specified by resRefName
895
     */
1015
     */
896
    private void addMsgDrvConnectionFactoryReference(final String resRefName, final Map beans) 
1016
    private void addMsgDrvConnectionFactoryReference(final String connectionFactoryName, final String mdbName) 
897
    throws ConfigurationException 
1017
    throws ConfigurationException 
898
    {
1018
    {
899
        modifyJboss(new JbossModifier() {
1019
        modifyJboss(new JbossModifier() {
900
           public void modify(Jboss modifiedJboss) {
1020
           public void modify(Jboss modifiedJboss) {
901
               String jndiName = JBOSS4_CONN_FACTORY_JNDI_NAME;
1021
               String jndiName = JBOSS4_CONN_FACTORY_JNDI_NAME;
902
               JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, resRefName, beans, jndiName);
1022
               JbossDataSourceRefModifier.modifyMsgDrv(modifiedJboss, connectionFactoryName, mdbName, jndiName);
903
           }
1023
           }
904
        });
1024
        });
905
    }
1025
    }
906
    
1026
    
1027
    public void bindMessageDestinationReferenceForEjb(String ejbName, String ejbType,
1028
            String referenceName, String connectionFactoryName,
1029
            String destName, MessageDestination.Type type) throws ConfigurationException {
1030
    
1031
        Set beanNames = new HashSet();
1032
        beanNames.add(ejbName);
1033
        
1034
        String destPrefix = null;
1035
        if (MessageDestination.Type.QUEUE.equals(type)) {
1036
            destPrefix = "queue/";
1037
        }
1038
        else
1039
        if (MessageDestination.Type.TOPIC.equals(type)) {
1040
            destPrefix = "topic/";
1041
        }
1042
        
1043
        if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.SESSION.equals(ejbType)) {
1044
            addConnectionFactoryReference(connectionFactoryName, beanNames, BEAN_TYPE.SESSION);
1045
            addMsgDestReference(referenceName, destPrefix, destName, beanNames, BEAN_TYPE.SESSION);
1046
        }
1047
        else
1048
        if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.ENTITY.equals(ejbType)) {
1049
            addConnectionFactoryReference(connectionFactoryName, beanNames, BEAN_TYPE.ENTITY);
1050
            addMsgDestReference(referenceName, destPrefix, destName, beanNames, BEAN_TYPE.ENTITY);
1051
        }
1052
        else
1053
        if (org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans.MESSAGE_DRIVEN.equals(ejbType)) {
1054
            addMsgDrvConnectionFactoryReference(connectionFactoryName, ejbName);
1055
            addMsgDrvMsgDestReference(referenceName, destPrefix, destName, ejbName);
1056
        }
1057
        
1058
    }
1059
    
1060
    
907
    /**
1061
    /**
908
     * Add a new message destination reference to the beans of the given type without it.
1062
     * Add a new message destination reference to the beans of the given type without it.
909
     * 
1063
     * 
910
     * @param msgDestRefName message destination reference name
1064
     * @param msgDestRefName message destination reference name
1065
     * @param destName message destination name
1066
     * @param detPrefix message destination prefix (queue/ ot topic/)
911
     * @param beanNames the beans (ejb-name value) which might need to add message destination reference specified by msgDestRefName
1067
     * @param beanNames the beans (ejb-name value) which might need to add message destination reference specified by msgDestRefName
912
     * @param beanType type of bean to add message destination reference to
1068
     * @param beanType type of bean to add message destination reference to
913
     */
1069
     */
914
    private void addMsgDestReference(final String msgDestRefName, final String destPrefix,
1070
    private void addMsgDestReference(final String msgDestRefName, final String destPrefix, final String destName,
915
                                     final Set beanNames, final BEAN_TYPE beanType) throws ConfigurationException 
1071
                                     final Set beanNames, final BEAN_TYPE beanType) throws ConfigurationException 
916
    {
1072
    {
917
        modifyJboss(new JbossModifier() {
1073
        modifyJboss(new JbossModifier() {
918
           public void modify(Jboss modifiedJboss) {
1074
           public void modify(Jboss modifiedJboss) {
919
               JbossMsgDestRefModifier.modify(modifiedJboss, msgDestRefName, beanNames, beanType, destPrefix);
1075
               JbossMsgDestRefModifier.modify(modifiedJboss, msgDestRefName, beanNames, beanType, destPrefix, destName);
920
           }
1076
           }
921
        });
1077
        });
922
    }
1078
    }
Lines 925-939 Link Here
925
     * Add a new message destination reference to the message driven beans without it.
1081
     * Add a new message destination reference to the message driven beans without it.
926
     * 
1082
     * 
927
     * @param msgDestRefName message destination reference name
1083
     * @param msgDestRefName message destination reference name
928
     * @param beanNames the beans (ejb-name value) which might need to add message destination reference specified by msgDestRefName
1084
     * @param destName message destination name
929
     * @param beanType type of bean to add message destination reference to
1085
     * @param destPrefix message destination prefix (queue/ ot topic/)
1086
     * @param mdbName the MDB (ejb-name value) which might need to add 
1087
     *        message destination reference specified by msgDestRefName
930
     */
1088
     */
931
    private void addMsgDrvMsgDestReference(final String msgDestRefName, final String destPrefix,
1089
    private void addMsgDrvMsgDestReference(final String msgDestRefName, final String destPrefix,
932
                                     final Map beans) throws ConfigurationException 
1090
                                     final String destName, final String mdbName) throws ConfigurationException 
933
    {
1091
    {
934
        modifyJboss(new JbossModifier() {
1092
        modifyJboss(new JbossModifier() {
935
           public void modify(Jboss modifiedJboss) {
1093
           public void modify(Jboss modifiedJboss) {
936
               JbossMsgDestRefModifier.modifyMsgDrv(modifiedJboss, msgDestRefName, beans, destPrefix);
1094
               JbossMsgDestRefModifier.modifyMsgDrv(modifiedJboss, msgDestRefName, mdbName, destPrefix, destName);
937
           }
1095
           }
938
        });
1096
        });
939
    }
1097
    }
(-)serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JBDeploymentConfiguration.java (-10 / +54 lines)
Lines 13-19 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
19
Lines 25-47 Link Here
25
import java.io.ByteArrayOutputStream;
25
import java.io.ByteArrayOutputStream;
26
import java.io.File;
26
import java.io.File;
27
import java.io.IOException;
27
import java.io.IOException;
28
import java.io.InputStream;
29
import java.io.OutputStream;
28
import java.io.OutputStream;
30
import java.util.HashSet;
29
import java.util.HashSet;
31
import java.util.Set;
30
import java.util.Set;
32
import javax.enterprise.deploy.model.DDBeanRoot;
33
import javax.enterprise.deploy.spi.DConfigBeanRoot;
34
import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException;
35
import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException;
36
import javax.swing.text.BadLocationException;
31
import javax.swing.text.BadLocationException;
37
import javax.swing.text.StyledDocument;
32
import javax.swing.text.StyledDocument;
38
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
33
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
39
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
34
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
40
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
35
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
36
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
41
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
37
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
42
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DatasourceConfiguration;
38
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DatasourceConfiguration;
39
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.MessageDestinationConfiguration;
43
import org.netbeans.modules.j2ee.jboss4.config.gen.Datasources;
40
import org.netbeans.modules.j2ee.jboss4.config.gen.Datasources;
44
import org.netbeans.modules.j2ee.jboss4.config.gen.LocalTxDatasource;
41
import org.netbeans.modules.j2ee.jboss4.config.gen.LocalTxDatasource;
42
import org.netbeans.modules.j2ee.jboss4.config.mdb.MessageDestinationSupport;
45
import org.netbeans.modules.schema2beans.BaseBean;
43
import org.netbeans.modules.schema2beans.BaseBean;
46
import org.openide.DialogDisplayer;
44
import org.openide.DialogDisplayer;
47
import org.openide.ErrorManager;
45
import org.openide.ErrorManager;
Lines 62-70 Link Here
62
/** 
60
/** 
63
 * Base for JBoss DeploymentConfiguration implementations.
61
 * Base for JBoss DeploymentConfiguration implementations.
64
 *
62
 *
65
 * @author  Pavel Buzek, lkotouc
63
 * @author  Pavel Buzek, Libor Kotouc
66
 */
64
 */
67
public abstract class JBDeploymentConfiguration implements DatasourceConfiguration {
65
public abstract class JBDeploymentConfiguration 
66
        implements DatasourceConfiguration, MessageDestinationConfiguration {
67
68
    
68
    
69
    protected static final String JBOSS4_DATASOURCE_JNDI_PREFIX = "java:"; // NOI18N
69
    protected static final String JBOSS4_DATASOURCE_JNDI_PREFIX = "java:"; // NOI18N
70
    protected static final String JBOSS4_MAIL_SERVICE_JNDI_NAME = "java:Mail"; // NOI18N
70
    protected static final String JBOSS4_MAIL_SERVICE_JNDI_NAME = "java:Mail"; // NOI18N
Lines 92-97 Link Here
92
    //cached data object for the data source file
92
    //cached data object for the data source file
93
    private DataObject datasourcesDO;
93
    private DataObject datasourcesDO;
94
    
94
    
95
     //support for message destination resources
96
    private MessageDestinationSupport destSupport;
97
    
95
    /** Creates a new instance of JBDeploymentConfiguration */
98
    /** Creates a new instance of JBDeploymentConfiguration */
96
    public JBDeploymentConfiguration (J2eeModule j2eeModule) {
99
    public JBDeploymentConfiguration (J2eeModule j2eeModule) {
97
        this.j2eeModule = j2eeModule;
100
        this.j2eeModule = j2eeModule;
Lines 114-120 Link Here
114
    
117
    
115
    // helper methods -------------------------------------------------
118
    // helper methods -------------------------------------------------
116
    
119
    
117
    protected void writefile(final File file, final BaseBean bean) throws ConfigurationException {
120
    public static void writeFile(final File file, final BaseBean bean) throws ConfigurationException {
118
        try {
121
        try {
119
            FileObject cfolder = FileUtil.toFileObject(file.getParentFile());
122
            FileObject cfolder = FileUtil.toFileObject(file.getParentFile());
120
            if (cfolder == null) {
123
            if (cfolder == null) {
Lines 261-267 Link Here
261
            } else {
264
            } else {
262
                // create jboss-ds.xml if it does not exist yet
265
                // create jboss-ds.xml if it does not exist yet
263
                datasources = new Datasources();
266
                datasources = new Datasources();
264
                writefile(datasourcesFile, datasources);
267
                writeFile(datasourcesFile, datasources);
265
            }
268
            }
266
        } catch (ConfigurationException ce) {
269
        } catch (ConfigurationException ce) {
267
            ErrorManager.getDefault().notify(ce);
270
            ErrorManager.getDefault().notify(ce);
Lines 408-412 Link Here
408
        });
411
        });
409
    }
412
    }
410
    
413
    
414
    public void bindDatasourceReference(String referenceName, String jndiName) throws ConfigurationException {}
415
    
416
    public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, 
417
            String referenceName, String jndiName) throws ConfigurationException {}
418
419
    public String findDatasourceJndiName(String referenceName) throws ConfigurationException {
420
        return null;
421
    }
422
    
423
    public String findDatasourceJndiNameForEjb(String ejbName, String referenceName) throws ConfigurationException {
424
        return null;
425
    }
426
    
427
    private MessageDestinationSupport getMessageDestinationsSupport() {
428
        if (destSupport == null) {
429
            destSupport = new MessageDestinationSupport(resourceDir);
430
        }
431
        return destSupport;
432
    }
433
   
434
    public Set<MessageDestination> getMessageDestinations() throws ConfigurationException {
435
        return getMessageDestinationsSupport().getMessageDestinations();
436
    }
437
438
    public MessageDestination createMessageDestination(String name, MessageDestination.Type type) 
439
    throws UnsupportedOperationException, ConfigurationException {
440
        return getMessageDestinationsSupport().createMessageDestination(name, type);
441
    }
442
    
443
    public void bindMdbToMessageDestination(String mdbName, String name, MessageDestination.Type type) throws ConfigurationException {}
444
445
    public String findMessageDestinationName(String mdbName) throws ConfigurationException {
446
        return null;
447
    }
448
449
    public void bindMessageDestinationReference(String referenceName, String connectionFactoryName, 
450
            String destName, MessageDestination.Type type) throws ConfigurationException {}
451
452
    public void bindMessageDestinationReferenceForEjb(String ejbName, String ejbType,
453
            String referenceName, String connectionFactoryName,
454
            String destName, MessageDestination.Type type) throws ConfigurationException {}
411
    
455
    
412
}
456
}
(-)serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JBossDatasourceManager.java (-2 / +10 lines)
Lines 13-19 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
19
Lines 90-96 Link Here
90
            FileObject dsFO = (FileObject)it.next();
90
            FileObject dsFO = (FileObject)it.next();
91
            File dsFile = FileUtil.toFile(dsFO);
91
            File dsFile = FileUtil.toFile(dsFO);
92
            try {
92
            try {
93
                Datasources ds = Datasources.createGraph(dsFile);
93
                Datasources ds = null;
94
                try {
95
                    ds = Datasources.createGraph(dsFile);
96
                } catch (RuntimeException re) {
97
                    // most likely not a data source (e.g. jms-ds.xml in JBoss 5.x)
98
                    String msg = NbBundle.getMessage(JBossDatasourceManager.class, "MSG_NotParseableDatasources", dsFile.getAbsolutePath());
99
                    ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, msg);
100
                    continue;
101
                }
94
                LocalTxDatasource ltxds[] = ds.getLocalTxDatasource();
102
                LocalTxDatasource ltxds[] = ds.getLocalTxDatasource();
95
                for (int i = 0; i < ltxds.length; i++) {
103
                for (int i = 0; i < ltxds.length; i++) {
96
                    if (ltxds[i].getJndiName().length() > 0) {
104
                    if (ltxds[i].getJndiName().length() > 0) {
(-)serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JbossDataSourceRefModifier.java (+40 lines)
Lines 259-263 Link Here
259
        }
259
        }
260
260
261
    }
261
    }
262
263
    /**
264
     * Add a reference to the given resource to the message-driven bean if it does not exist yet.
265
     *
266
     * @param modifiedJboss Jboss graph instance being modified
267
     * @param resRefName resource reference name
268
     * @param mdbName the MDB (ejb-name) which might need to add resource reference specified by resRefName
269
     * @param jndiName JNDI name of the resource
270
     */
271
    static void modifyMsgDrv(Jboss modifiedJboss, String resRefName, String mdbName, String jndiName) {
272
273
        if (modifiedJboss.getEnterpriseBeans() == null)
274
            modifiedJboss.setEnterpriseBeans(new EnterpriseBeans());
275
276
        addMsgDrvResReference(modifiedJboss, resRefName, mdbName, jndiName);
277
    }
278
    
279
    private static void addMsgDrvResReference(Jboss modifiedJboss, String resRefName, String mdbName, String jndiName) {
280
281
        EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans();
282
283
        for (MessageDriven mdb : eb.getMessageDriven()) {
284
            String ejbName = mdb.getEjbName();
285
            if (mdbName.equals(ejbName)) { // msgdrv found -> check whether it has the resource-ref
286
                ResourceRef[] resourceRefs = mdb.getResourceRef();
287
                int j = 0;
288
                for ( ; j < resourceRefs.length; j++) {
289
                    String rrn = resourceRefs[j].getResRefName();
290
                    if (resRefName.equals(rrn))
291
                        return; // resource-ref found
292
                }
293
                if (j == resourceRefs.length) {// resource-ref not found
294
                    ResourceRef newRR = new ResourceRef();
295
                    newRR.setResRefName(resRefName);
296
                    newRR.setJndiName(jndiName);
297
                    mdb.addResourceRef(newRR);
298
                }
299
            }
300
        }
301
    }
262
    
302
    
263
}
303
}
(-)serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/JbossMsgDestRefModifier.java (-13 / +59 lines)
Lines 53-60 Link Here
53
     * @param beanNames the beans (ejb-name value) which might need to add message destination reference specified by msgDestRefName
53
     * @param beanNames the beans (ejb-name value) which might need to add message destination reference specified by msgDestRefName
54
     * @param beanType type of bean to add message destination reference to
54
     * @param beanType type of bean to add message destination reference to
55
     * @param destPrefix prefix of the message destination
55
     * @param destPrefix prefix of the message destination
56
     * @param destName message destination name
56
     */
57
     */
57
    static void modify(Jboss modifiedJboss, String msgDestRefName, Set beanNames, BEAN_TYPE beanType, String destPrefix) {
58
    static void modify(Jboss modifiedJboss, String msgDestRefName, Set beanNames, 
59
            BEAN_TYPE beanType, String destPrefix, String destName) {
58
60
59
        assert(beanNames.size() > 0);
61
        assert(beanNames.size() > 0);
60
62
Lines 62-71 Link Here
62
            modifiedJboss.setEnterpriseBeans(new EnterpriseBeans());
64
            modifiedJboss.setEnterpriseBeans(new EnterpriseBeans());
63
65
64
        if (beanType == BEAN_TYPE.SESSION) {
66
        if (beanType == BEAN_TYPE.SESSION) {
65
            addSessionMsgDestReference(modifiedJboss, msgDestRefName, beanNames, destPrefix);
67
            addSessionMsgDestReference(modifiedJboss, msgDestRefName, beanNames, destPrefix, destName);
66
        } else
68
        } else
67
        if (beanType == BEAN_TYPE.ENTITY) {
69
        if (beanType == BEAN_TYPE.ENTITY) {
68
            addEntityMsgDestReference(modifiedJboss, msgDestRefName, beanNames, destPrefix);
70
            addEntityMsgDestReference(modifiedJboss, msgDestRefName, beanNames, destPrefix, destName);
69
        }
71
        }
70
    }
72
    }
71
    
73
    
Lines 76-83 Link Here
76
     * @param resRefName message destination reference name
78
     * @param resRefName message destination reference name
77
     * @param sessionNames the sessions (ejb-name value) which might need to add message destination reference specified by msgDestRefName
79
     * @param sessionNames the sessions (ejb-name value) which might need to add message destination reference specified by msgDestRefName
78
     * @param destPrefix prefix of the message destination
80
     * @param destPrefix prefix of the message destination
81
     * @param destName message destination name
79
     */
82
     */
80
    private static void addSessionMsgDestReference(Jboss modifiedJboss, String msgDestRefName, Set sessionNames, String destPrefix) {
83
    private static void addSessionMsgDestReference(Jboss modifiedJboss, String msgDestRefName, 
84
            Set sessionNames, String destPrefix, String destName) {
81
85
82
        List/*<Session>*/ sesssionsWithoutReference = new LinkedList();
86
        List/*<Session>*/ sesssionsWithoutReference = new LinkedList();
83
87
Lines 119-125 Link Here
119
        for (Iterator it = sesssionsWithoutReference.iterator(); it.hasNext(); ) {
123
        for (Iterator it = sesssionsWithoutReference.iterator(); it.hasNext(); ) {
120
            MessageDestinationRef mdr = new MessageDestinationRef();
124
            MessageDestinationRef mdr = new MessageDestinationRef();
121
            mdr.setMessageDestinationRefName(msgDestRefName);
125
            mdr.setMessageDestinationRefName(msgDestRefName);
122
            String jndiName = getJndiName(msgDestRefName, destPrefix);
126
            String jndiName = getJndiName(destName, destPrefix);
123
            mdr.setJndiName(jndiName);
127
            mdr.setJndiName(jndiName);
124
            Session session = (Session)it.next();
128
            Session session = (Session)it.next();
125
            session.addMessageDestinationRef(mdr);
129
            session.addMessageDestinationRef(mdr);
Lines 134-141 Link Here
134
     * @param resRefName message destination reference name
138
     * @param resRefName message destination reference name
135
     * @param sessionNames the entities (ejb-name value) which might need to add message destination reference specified by msgDestRefName
139
     * @param sessionNames the entities (ejb-name value) which might need to add message destination reference specified by msgDestRefName
136
     * @param destPrefix prefix of the message destination
140
     * @param destPrefix prefix of the message destination
141
     * @param destName message destination name
137
     */
142
     */
138
    private static void addEntityMsgDestReference(Jboss modifiedJboss, String msgDestRefName, Set entityNames, String destPrefix) {
143
    private static void addEntityMsgDestReference(Jboss modifiedJboss, String msgDestRefName, 
144
            Set entityNames, String destPrefix, String destName) {
139
145
140
        List/*<Entity>*/ entitiesWithoutReference = new LinkedList();
146
        List/*<Entity>*/ entitiesWithoutReference = new LinkedList();
141
147
Lines 177-183 Link Here
177
        for (Iterator it = entitiesWithoutReference.iterator(); it.hasNext(); ) {
183
        for (Iterator it = entitiesWithoutReference.iterator(); it.hasNext(); ) {
178
            MessageDestinationRef mdr = new MessageDestinationRef();
184
            MessageDestinationRef mdr = new MessageDestinationRef();
179
            mdr.setMessageDestinationRefName(msgDestRefName);
185
            mdr.setMessageDestinationRefName(msgDestRefName);
180
            String jndiName = getJndiName(msgDestRefName, destPrefix);
186
            String jndiName = getJndiName(destName, destPrefix);
181
            mdr.setJndiName(jndiName);
187
            mdr.setJndiName(jndiName);
182
            Entity entity = (Entity)it.next();
188
            Entity entity = (Entity)it.next();
183
            entity.addMessageDestinationRef(mdr);
189
            entity.addMessageDestinationRef(mdr);
Lines 262-274 Link Here
262
268
263
    }
269
    }
264
    
270
    
265
    private static String getJndiName(String msgDestRefName, String destPrefix) {
271
    /**
266
        String jndiName = msgDestRefName;
272
     * Add a reference to the given message destination to the message-driven beans if it does not exist yet.
267
        // 'jms/' prefix automatically prepended to the selected message destination during 'Send JMS Message' action
273
     *
268
        if (msgDestRefName.startsWith("jms/")) // NOI18N
274
     * @param modifiedJboss Jboss graph instance being modified
269
            jndiName = destPrefix + msgDestRefName.substring("jms/".length()); //replace 'jms/' with the correct prefix
275
     * @param msgDestRefName message destination reference name
276
     * @param mdbName the MDB (ejb-name value) which might need to add message 
277
     *        destination reference specified by msgDestRefName
278
     * @param destPrefix prefix of the message destination
279
     * @param destName message destination name
280
     */
281
    static void modifyMsgDrv(Jboss modifiedJboss, String msgDestRefName, 
282
            String mdbName, String destPrefix, String destName) {
270
283
271
        return jndiName;
284
        if (modifiedJboss.getEnterpriseBeans() == null)
285
            modifiedJboss.setEnterpriseBeans(new EnterpriseBeans());
286
287
        addMsgDrvMsgDestReference(modifiedJboss, msgDestRefName, mdbName, destPrefix, destName);
288
    }
289
    
290
    private static void addMsgDrvMsgDestReference(Jboss modifiedJboss, String msgDestRefName, 
291
            String mdbName, String destPrefix, String destName) {
292
293
        EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans();
294
295
        for (MessageDriven mdb : eb.getMessageDriven()) {
296
            String ejbName = mdb.getEjbName();
297
            if (mdbName.equals(ejbName)) { // msgdrv found -> check whether it has the message-destination-ref
298
                MessageDestinationRef[] msgDestRefs = mdb.getMessageDestinationRef();
299
                int j = 0;
300
                for ( ; j < msgDestRefs.length; j++) {
301
                    String mdrn = msgDestRefs[j].getMessageDestinationRefName();
302
                    if (msgDestRefName.equals(mdrn))
303
                        return; // message-destination-ref found
304
                }
305
                if (j == msgDestRefs.length) { // message-destination-ref not found
306
                    MessageDestinationRef mdr = new MessageDestinationRef();
307
                    mdr.setMessageDestinationRefName(msgDestRefName);
308
                    String jndiName = getJndiName(destName, destPrefix);
309
                    mdr.setJndiName(jndiName);
310
                    mdb.addMessageDestinationRef(mdr);
311
                }
312
            }
313
        }
314
    }
315
    
316
    private static String getJndiName(String destName, String destPrefix) {
317
        return destPrefix + destName;
272
    }
318
    }
273
    
319
    
274
}
320
}
(-)serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/WarDeploymentConfiguration.java (-10 / +46 lines)
Lines 13-19 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
19
Lines 29-34 Link Here
29
import javax.swing.text.StyledDocument;
29
import javax.swing.text.StyledDocument;
30
import org.netbeans.modules.j2ee.dd.api.web.WebApp;
30
import org.netbeans.modules.j2ee.dd.api.web.WebApp;
31
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
31
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
32
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
32
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
33
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
33
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ContextRootConfiguration;
34
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ContextRootConfiguration;
34
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DatasourceConfiguration;
35
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.DatasourceConfiguration;
Lines 54-60 Link Here
54
 * Web module deployment configuration handles creation and updating of the 
55
 * Web module deployment configuration handles creation and updating of the 
55
 * jboss-web.xml configuration file.
56
 * jboss-web.xml configuration file.
56
 *
57
 *
57
 * @author sherold, lkotouc
58
 * @author Stepan Herold, Libor Kotouc
58
 */
59
 */
59
public class WarDeploymentConfiguration extends JBDeploymentConfiguration 
60
public class WarDeploymentConfiguration extends JBDeploymentConfiguration 
60
implements ModuleConfiguration, ContextRootConfiguration, DatasourceConfiguration, 
61
implements ModuleConfiguration, ContextRootConfiguration, DatasourceConfiguration, 
Lines 100-105 Link Here
100
        return true;
101
        return true;
101
    }
102
    }
102
    
103
    
104
    public boolean supportsCreateMessageDestination() {
105
        return true;
106
    }
107
103
    /**
108
    /**
104
     * Return context path.
109
     * Return context path.
105
     * 
110
     * 
Lines 162-168 Link Here
162
                try {
167
                try {
163
                    String resType = resourceRef.getResType();
168
                    String resType = resourceRef.getResType();
164
                    if ("javax.sql.DataSource".equals(resType)) { // NOI18N
169
                    if ("javax.sql.DataSource".equals(resType)) { // NOI18N
165
                        addResReference(resourceRef.getResRefName());
170
                        addResReference(resourceRef.getResRefName(), JBOSS4_DATASOURCE_JNDI_PREFIX + resourceRef.getResRefName());
166
                    } else if ("javax.mail.Session".equals(resType)) { // NOI18N
171
                    } else if ("javax.mail.Session".equals(resType)) { // NOI18N
167
                        addMailReference(resourceRef.getResRefName());
172
                        addMailReference(resourceRef.getResRefName());
168
                    } else if ("javax.jms.ConnectionFactory".equals(resType)) { // NOI18N
173
                    } else if ("javax.jms.ConnectionFactory".equals(resType)) { // NOI18N
Lines 197-208 Link Here
197
        }
202
        }
198
    }
203
    }
199
    
204
    
205
    public void bindDatasourceReference(String referenceName, String jndiName) throws ConfigurationException {
206
        addResReference(referenceName, jndiName);
207
    }
208
    
209
    public String findDatasourceJndiName(String referenceName) throws ConfigurationException {
210
        
211
        ResourceRef resourceRefs[] = getJbossWeb().getResourceRef();
212
        for (ResourceRef resourceRef : resourceRefs) {
213
            String rrn = resourceRef.getResRefName();
214
            if (referenceName.equals(rrn)) {
215
                return resourceRef.getJndiName();
216
            }
217
        }
218
        
219
        return null;
220
    }
221
200
    /**
222
    /**
201
     * Add a new resource reference.
223
     * Add a new resource reference.
202
     * 
224
     * 
203
     * @param name resource reference name
225
     * @param name resource reference name
204
     */
226
     */
205
    private void addResReference(final String name) throws ConfigurationException {
227
    private void addResReference(final String name, final String jndiName) throws ConfigurationException {
206
        modifyJbossWeb(new JbossWebModifier() {
228
        modifyJbossWeb(new JbossWebModifier() {
207
            public void modify(JbossWeb modifiedJbossWeb) {
229
            public void modify(JbossWeb modifiedJbossWeb) {
208
230
Lines 219-225 Link Here
219
                //if it doesn't exist yet, create a new one
241
                //if it doesn't exist yet, create a new one
220
                ResourceRef newRR = new ResourceRef();
242
                ResourceRef newRR = new ResourceRef();
221
                newRR.setResRefName(name);
243
                newRR.setResRefName(name);
222
                newRR.setJndiName(JBOSS4_DATASOURCE_JNDI_PREFIX + name);
244
                newRR.setJndiName(jndiName);
223
                modifiedJbossWeb.addResourceRef(newRR);
245
                modifiedJbossWeb.addResourceRef(newRR);
224
            }
246
            }
225
        });
247
        });
Lines 253-258 Link Here
253
        });
275
        });
254
    }
276
    }
255
    
277
    
278
    public void bindMessageDestinationReference(String referenceName, String connectionFactoryName, 
279
            String destName, MessageDestination.Type type) throws ConfigurationException {
280
281
        addConnectionFactoryReference(connectionFactoryName);
282
        
283
        String jndiName = null;
284
        if (MessageDestination.Type.QUEUE.equals(type)) {
285
            jndiName = "queue/" + destName;
286
        }
287
        else
288
        if (MessageDestination.Type.TOPIC.equals(type)) {
289
            jndiName = "topic/" + destName;
290
        }
291
292
        addMsgDestReference(referenceName, jndiName);
293
    }
294
    
256
    /**
295
    /**
257
     * Add a new connection factory reference.
296
     * Add a new connection factory reference.
258
     * 
297
     * 
Lines 287-293 Link Here
287
     * @param name message destination name
326
     * @param name message destination name
288
     * @param destPrefix MDB destination prefix
327
     * @param destPrefix MDB destination prefix
289
     */
328
     */
290
    private void addMsgDestReference(final String name, final String destPrefix) throws ConfigurationException {
329
    private void addMsgDestReference(final String name, final String jndiName) throws ConfigurationException {
291
        modifyJbossWeb(new JbossWebModifier() {
330
        modifyJbossWeb(new JbossWebModifier() {
292
            public void modify(JbossWeb modifiedJbossWeb) {
331
            public void modify(JbossWeb modifiedJbossWeb) {
293
332
Lines 304-312 Link Here
304
                //if it doesn't exist yet, create a new one
343
                //if it doesn't exist yet, create a new one
305
                MessageDestinationRef mdr = new MessageDestinationRef();
344
                MessageDestinationRef mdr = new MessageDestinationRef();
306
                mdr.setMessageDestinationRefName(name);
345
                mdr.setMessageDestinationRefName(name);
307
                String jndiName = name;
308
                if (name.startsWith("jms/")) // prefix automatically prepended to the selected message destination during 'Send JMS Message' action
309
                    jndiName = destPrefix + name.substring("jms/".length()); //replace 'jms/' with the correct prefix
310
                mdr.setJndiName(jndiName);
346
                mdr.setJndiName(jndiName);
311
                modifiedJbossWeb.addMessageDestinationRef(mdr);
347
                modifiedJbossWeb.addMessageDestinationRef(mdr);
312
            }
348
            }
Lines 366-372 Link Here
366
                } else {
402
                } else {
367
                    // create jboss-web.xml if it does not exist yet
403
                    // create jboss-web.xml if it does not exist yet
368
                    jbossWeb = generateJbossWeb();
404
                    jbossWeb = generateJbossWeb();
369
                    writefile(jbossWebFile, jbossWeb);
405
                    writeFile(jbossWebFile, jbossWeb);
370
                }
406
                }
371
            } catch (ConfigurationException ce) {
407
            } catch (ConfigurationException ce) {
372
                ErrorManager.getDefault().notify(ce);
408
                ErrorManager.getDefault().notify(ce);
(-)serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestination.java (+46 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.j2ee.jboss4.config.mdb;
21
22
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
23
24
/**
25
 *
26
 * @author Libor Kotouc
27
 */
28
public class JBossMessageDestination implements MessageDestination {
29
    
30
    private String name;
31
    private Type type;
32
    
33
    public JBossMessageDestination(String name, Type type) {
34
        this.name = name;
35
        this.type = type;
36
    }
37
38
    public String getName() {
39
        return name;
40
    }
41
42
    public Type getType() {
43
        return type;
44
    }
45
    
46
}
(-)serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/JBossMessageDestinationDeployment.java (+259 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.j2ee.jboss4.config.mdb;
21
22
import java.io.BufferedOutputStream;
23
import java.io.File;
24
import java.io.IOException;
25
import java.io.OutputStream;
26
import java.util.HashSet;
27
import java.util.Set;
28
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
29
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
30
import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
31
import org.netbeans.modules.j2ee.deployment.plugins.spi.MessageDestinationDeployment;
32
import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties;
33
import org.netbeans.modules.schema2beans.BaseBean;
34
import org.openide.filesystems.FileLock;
35
import org.openide.filesystems.FileObject;
36
import org.openide.filesystems.FileSystem;
37
import org.openide.filesystems.FileUtil;
38
39
/**
40
 *
41
 * @author Libor Kotouc
42
 */
43
public final class JBossMessageDestinationDeployment implements MessageDestinationDeployment {
44
    
45
//    private static final String DSdotXML = "-ds.xml"; // NOI18N
46
//    private static final String JBossDSdotXML = "jboss-ds.xml"; // NOI18N
47
    
48
    // server's deploy dir
49
    private FileObject deployDir;
50
    
51
    public JBossMessageDestinationDeployment(String serverUrl) {
52
        String serverDirPath = InstanceProperties.getInstanceProperties(serverUrl).
53
                                        getProperty(JBPluginProperties.PROPERTY_DEPLOY_DIR);
54
        deployDir = FileUtil.toFileObject(new File(serverDirPath));
55
    }
56
    
57
    public Set<MessageDestination> getMessageDestinations() throws ConfigurationException {
58
        HashSet<MessageDestination> destinations = new HashSet<MessageDestination>();
59
        destinations.add(new JBossMessageDestination("SampleServerQueue", MessageDestination.Type.QUEUE));
60
        destinations.add(new JBossMessageDestination("SampleServerTopic", MessageDestination.Type.TOPIC));
61
        return destinations;
62
    }
63
64
    public void deployMessageDestinations(Set<MessageDestination> destinations) throws ConfigurationException {
65
    }
66
    
67
    
68
/*  
69
    public Set<Datasource> getDatasources() throws ConfigurationException {
70
        
71
        Set<Datasource> datasources = new HashSet<Datasource>();
72
        
73
        if (deployDir == null || !deployDir.isValid() || !deployDir.isFolder() || !deployDir.canRead()) {
74
            ErrorManager.getDefault().log(ErrorManager.USER, 
75
                    NbBundle.getMessage(JBossMessageDestinationDeployment.class, "ERR_WRONG_DEPLOY_DIR"));
76
            return datasources;
77
        }
78
        
79
        Enumeration files = deployDir.getChildren(true);
80
        List<FileObject> confs = new LinkedList<FileObject>();
81
        while (files.hasMoreElements()) { // searching for config files with DS
82
            FileObject file = (FileObject) files.nextElement();
83
            if (!file.isFolder() && file.getNameExt().endsWith(DSdotXML) && file.canRead())
84
                confs.add(file);
85
        }
86
        
87
        if (confs.size() == 0) // nowhere to search
88
            return datasources;
89
90
        for (Iterator it = confs.iterator(); it.hasNext();) {
91
            FileObject dsFO = (FileObject)it.next();
92
            File dsFile = FileUtil.toFile(dsFO);
93
            try {
94
                Datasources ds = null;
95
                try {
96
                    ds = Datasources.createGraph(dsFile);
97
                } catch (RuntimeException re) {
98
                    // most likely not a data source (e.g. jms-ds.xml in JBoss 5.x)
99
                    String msg = NbBundle.getMessage(JBossMessageDestinationDeployment.class, "MSG_NotParseableDatasources", dsFile.getAbsolutePath());
100
                    ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, msg);
101
                    continue;
102
                }
103
                LocalTxDatasource ltxds[] = ds.getLocalTxDatasource();
104
                for (int i = 0; i < ltxds.length; i++) {
105
                    if (ltxds[i].getJndiName().length() > 0) {
106
                        datasources.add(new JBossDatasource(
107
                                    ltxds[i].getJndiName(),
108
                                    ltxds[i].getConnectionUrl(),
109
                                    ltxds[i].getUserName(),
110
                                    ltxds[i].getPassword(),
111
                                    ltxds[i].getDriverClass()));
112
                    }
113
                }
114
            } catch (IOException ioe) {
115
                String msg = NbBundle.getMessage(JBossMessageDestinationDeployment.class, "MSG_CannotReadDatasources", dsFile.getAbsolutePath());
116
                throw new ConfigurationException(msg, ioe);
117
            } catch (RuntimeException re) {
118
                String msg = NbBundle.getMessage(JBossMessageDestinationDeployment.class, "MSG_NotParseableDatasources", dsFile.getAbsolutePath());
119
                throw new ConfigurationException(msg ,re);
120
            }
121
        }
122
        
123
        return datasources;
124
    }
125
126
    public void deployDatasources(Set<Datasource> datasources) 
127
    throws ConfigurationException, DatasourceAlreadyExistsException 
128
    {
129
        Set<Datasource> deployedDS = getDatasources();
130
        Map<String, Datasource> ddsMap = transform(deployedDS); // for faster searching
131
        
132
        HashMap<String, Datasource> newDS = new HashMap<String, Datasource>(); // will contain all ds which do not conflict with existing ones
133
        
134
        //resolve all conflicts
135
        LinkedList<Datasource> conflictDS = new LinkedList<Datasource>();
136
        for (Iterator<Datasource> it = datasources.iterator(); it.hasNext();) {
137
            Object o = it.next();
138
            if (!(o instanceof JBossDatasource))
139
                continue;
140
            JBossDatasource ds = (JBossDatasource)o;
141
            String jndiName = ds.getJndiName();
142
            if (ddsMap.keySet().contains(jndiName)) { // conflicting ds found
143
                if (!ddsMap.get(jndiName).equals(ds)) { // found ds is not equal
144
                    conflictDS.add(ddsMap.get(jndiName)); // NOI18N
145
                }
146
            }
147
            else if (jndiName != null) {
148
                newDS.put(jndiName, ds);
149
            }
150
        }
151
        
152
        if (conflictDS.size() > 0) { // conflict found -> exception
153
            throw new DatasourceAlreadyExistsException(conflictDS);
154
        }
155
        
156
        //write jboss-ds.xml
157
        FileObject dsXmlFo = serverDir.getFileObject(JBossDSdotXML);
158
        File dsXMLFile = (dsXmlFo != null ? FileUtil.toFile(dsXmlFo) : null);
159
160
        Datasources deployedDSGraph = null;
161
        try {
162
            deployedDSGraph = (dsXMLFile != null ? Datasources.createGraph(dsXMLFile) : new Datasources());
163
        }
164
        catch (IOException ioe) {
165
            ErrorManager.getDefault().annotate(ioe, NbBundle.getMessage(getClass(), "ERR_CannotReadDSdotXml"));
166
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
167
            return;
168
        }
169
170
        //merge ds graph with newDS - remove conflicting ds from graph
171
        LocalTxDatasource ltxds[] = deployedDSGraph.getLocalTxDatasource();
172
        for (int i = 0; i < ltxds.length; i++) {
173
            String jndiName = ltxds[i].getJndiName();
174
            if (newDS.keySet().contains(jndiName)) //conflict, we must remove it from graph
175
                deployedDSGraph.removeLocalTxDatasource(ltxds[i]);
176
        }
177
        
178
        //add all ds from newDS
179
        for (Iterator it = newDS.values().iterator(); it.hasNext();) {
180
            JBossDatasource ds = (JBossDatasource) it.next();
181
            
182
            LocalTxDatasource lds = new LocalTxDatasource();
183
            lds.setJndiName(ds.getJndiName());
184
            lds.setConnectionUrl(ds.getUrl());
185
            lds.setDriverClass(ds.getDriverClassName());
186
            lds.setUserName(ds.getUsername());
187
            lds.setPassword(ds.getPassword());
188
            lds.setMinPoolSize(ds.getMinPoolSize());
189
            lds.setMaxPoolSize(ds.getMaxPoolSize());
190
            lds.setIdleTimeoutMinutes(ds.getIdleTimeoutMinutes());
191
192
            deployedDSGraph.addLocalTxDatasource(lds);
193
        }
194
        
195
        //write modified graph into jboss-ds.xml
196
        if (newDS.size() > 0) {
197
            if (dsXMLFile == null) {
198
                try {
199
                    dsXmlFo = serverDir.createData(JBossDSdotXML);
200
                }
201
                catch (IOException ioe) {
202
                    ErrorManager.getDefault().annotate(ioe, NbBundle.getMessage(getClass(), "ERR_CannotCreateDSdotXml"));
203
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
204
                    return;
205
                }
206
                
207
                dsXMLFile = FileUtil.toFile(dsXmlFo);
208
            }
209
            
210
            writeFile(dsXMLFile, deployedDSGraph);            
211
        }        
212
        
213
    }
214
    
215
    private Map<String, Datasource> transform(Set<Datasource> datasources) {
216
        HashMap<String, Datasource> map = new HashMap<String, Datasource>();
217
        for (Iterator it = datasources.iterator(); it.hasNext();) {
218
            JBossDatasource ds = (JBossDatasource) it.next();
219
            if (ds.getJndiName() != null)
220
                map.put(ds.getJndiName(), ds);
221
        }
222
        return map;
223
    }
224
*/
225
    private void writeFile(final File file, final BaseBean bean) throws ConfigurationException {
226
        try {
227
228
            FileSystem fs = deployDir.getFileSystem();
229
            fs.runAtomicAction(new FileSystem.AtomicAction() {
230
                public void run() throws IOException {
231
                    OutputStream os = null;
232
                    FileLock lock = null;
233
                    try {
234
                        String name = file.getName();
235
                        FileObject configFO = deployDir.getFileObject(name);
236
                        if (configFO == null) {
237
                            configFO = deployDir.createData(name);
238
                        }
239
                        lock = configFO.lock();
240
                        os = new BufferedOutputStream (configFO.getOutputStream(lock), 4096);
241
                        // TODO notification needed
242
                        if (bean != null) {
243
                            bean.write(os);
244
                        }
245
                    } finally {
246
                        if (os != null) {
247
                            try { os.close(); } catch(IOException ioe) {}
248
                        }
249
                        if (lock != null) 
250
                            lock.releaseLock();
251
                    }
252
                }
253
            });
254
        } catch (IOException e) {
255
            throw new ConfigurationException (e.getLocalizedMessage ());
256
        }
257
    }
258
259
}
(-)serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/config/mdb/MessageDestinationSupport.java (+169 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
package org.netbeans.modules.j2ee.jboss4.config.mdb;
20
21
import java.io.File;
22
import java.io.IOException;
23
import java.util.Collections;
24
import java.util.HashSet;
25
import java.util.Set;
26
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
27
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
28
import org.netbeans.modules.j2ee.jboss4.config.JBDeploymentConfiguration;
29
import org.netbeans.modules.j2ee.jboss4.config.gen.Mbean;
30
import org.netbeans.modules.j2ee.jboss4.config.gen.Server;
31
import org.openide.ErrorManager;
32
import org.openide.filesystems.FileChangeAdapter;
33
import org.openide.filesystems.FileEvent;
34
import org.openide.filesystems.FileObject;
35
import org.openide.filesystems.FileUtil;
36
37
/**
38
 *
39
 * @author Libor Kotouc
40
 */
41
public class MessageDestinationSupport {
42
    
43
    public static String MSG_DEST_RESOURCE_NAME_JB4 = "netbeans-destinations-service.xml"; // NOI18N
44
    
45
    //model of the destination service file
46
    private Server destinationServiceModel;
47
    
48
    //destination service file (placed in the resourceDir)
49
    private File destinationsFile;
50
    
51
    //destination service file object
52
    private FileObject destinationsFO;
53
    
54
    public MessageDestinationSupport(File resourceDir) {
55
        this.destinationsFile = destinationsFile;
56
57
        destinationsFile = new File(resourceDir, MSG_DEST_RESOURCE_NAME_JB4);
58
        ensureDestinationsFOExists();
59
    }
60
    
61
    /**
62
     * Listener of netbeans-destinations-service.xml document changes.
63
     */
64
    private class MessageDestinationFileListener extends FileChangeAdapter {
65
        
66
        public void fileChanged(FileEvent fe) {
67
            assert(fe.getSource() == destinationsFO);
68
            destinationServiceModel = null;
69
        }
70
71
        public void fileDeleted(FileEvent fe) {
72
            assert(fe.getSource() == destinationsFO);
73
            destinationServiceModel = null;
74
        }
75
    } 
76
    
77
    private void ensureDestinationsFOExists() {
78
        if (!destinationsFile.exists()) {
79
            return;
80
        }
81
        if (destinationsFO == null || !destinationsFO.isValid()) {
82
            destinationsFO = FileUtil.toFileObject(destinationsFile);
83
            assert(destinationsFO != null);
84
            destinationsFO.addFileChangeListener(new MessageDestinationFileListener());
85
        }
86
    }
87
    
88
    public Set<MessageDestination> getMessageDestinations() throws ConfigurationException {
89
        
90
        Server server = getMessageDestinationGraph();
91
        if (server == null) {
92
            return Collections.<MessageDestination>emptySet();
93
        }
94
        
95
        HashSet<MessageDestination> destinations = new HashSet<MessageDestination>();
96
        
97
        for (Mbean mbean : destinationServiceModel.getMbean()) {
98
            String mbeanNameAttribute = mbean.getName();
99
            if (mbeanNameAttribute == null) {
100
                continue;
101
            }
102
            
103
            MessageDestination.Type type = null;
104
            if (mbeanNameAttribute.indexOf("service=Queue") > -1) { // NOI18N
105
                type = MessageDestination.Type.QUEUE;
106
            }
107
            else
108
            if (mbeanNameAttribute.indexOf("service=Topic") > -1) { // NOI18N
109
                type = MessageDestination.Type.TOPIC;
110
            }
111
            if (type == null) {
112
                continue;
113
            }
114
            
115
            int nameIndex = mbeanNameAttribute.indexOf("name="); // NOI18N
116
            if (nameIndex == -1) {
117
                continue;
118
            }
119
            
120
            String name = mbeanNameAttribute.substring(nameIndex + 5); // "name=".length() == 5
121
            if (name.indexOf(",") > -1) {
122
                name = name.substring(0, name.indexOf(",")); // NOI18N
123
            }
124
                
125
            destinations.add(new JBossMessageDestination(name, type));
126
        }
127
        
128
        return destinations;
129
    }
130
131
    public MessageDestination createMessageDestination(String name, MessageDestination.Type type) 
132
    throws UnsupportedOperationException, ConfigurationException {
133
        // TODO write into file
134
        return new JBossMessageDestination(name, type);
135
    }
136
    
137
    /**
138
     * Return destination service graph. If it was not created yet, load it from the file
139
     * and cache it. If the file does not exist, generate it.
140
     *
141
     * @return Destination service graph or null if the netbeans-destinations-service.xml file is not parseable.
142
     */
143
    private synchronized Server getMessageDestinationGraph() {
144
        
145
        try {
146
            if (destinationsFile.exists()) {
147
                // load configuration if already exists
148
                try {
149
                    if (destinationServiceModel == null)
150
                        destinationServiceModel = Server.createGraph(destinationsFile);
151
                } catch (IOException ioe) {
152
                    ErrorManager.getDefault().notify(ioe);
153
                } catch (RuntimeException re) {
154
                    // netbeans-destinations-service.xml is not parseable, do nothing
155
                }
156
            } else {
157
                // create netbeans-destinations-service.xml if it does not exist yet
158
                destinationServiceModel = new Server();
159
                JBDeploymentConfiguration.writeFile(destinationsFile, destinationServiceModel);
160
                ensureDestinationsFOExists();
161
            }
162
        } catch (ConfigurationException ce) {
163
            ErrorManager.getDefault().notify(ce);
164
        }
165
166
        return destinationServiceModel;
167
    }
168
    
169
}
(-)serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBOptionalDeploymentManagerFactory.java (-1 / +12 lines)
Lines 13-23 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
package org.netbeans.modules.j2ee.jboss4.ide;
19
package org.netbeans.modules.j2ee.jboss4.ide;
20
20
21
import org.netbeans.modules.j2ee.deployment.plugins.spi.MessageDestinationDeployment;
21
import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager;
22
import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager;
22
import org.netbeans.modules.j2ee.deployment.plugins.spi.DatasourceManager;
23
import org.netbeans.modules.j2ee.deployment.plugins.spi.DatasourceManager;
23
import org.netbeans.modules.j2ee.jboss4.config.JBossDatasourceManager;
24
import org.netbeans.modules.j2ee.jboss4.config.JBossDatasourceManager;
Lines 27-32 Link Here
27
import org.netbeans.modules.j2ee.deployment.plugins.spi.IncrementalDeployment;
28
import org.netbeans.modules.j2ee.deployment.plugins.spi.IncrementalDeployment;
28
import org.netbeans.modules.j2ee.deployment.plugins.spi.OptionalDeploymentManagerFactory;
29
import org.netbeans.modules.j2ee.deployment.plugins.spi.OptionalDeploymentManagerFactory;
29
import org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer;
30
import org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer;
31
import org.netbeans.modules.j2ee.jboss4.config.mdb.JBossMessageDestinationDeployment;
30
import org.openide.WizardDescriptor.InstantiatingIterator;
32
import org.openide.WizardDescriptor.InstantiatingIterator;
31
33
32
/**
34
/**
Lines 61-65 Link Here
61
        
63
        
62
        return dsMgr;
64
        return dsMgr;
63
    }
65
    }
66
67
    public MessageDestinationDeployment getMessageDestinationDeployment(DeploymentManager dm) {
68
        if (!(dm instanceof JBDeploymentManager)) {
69
            throw new IllegalArgumentException("");
70
        }
71
72
        return new JBossMessageDestinationDeployment(((JBDeploymentManager)dm).getUrl());
73
    }
74
    
64
    
75
    
65
}
76
}
(-)serverplugins/jboss4/src/org/netbeans/modules/j2ee/jboss4/resources/jboss-service_4_0.dtd (+287 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8' ?>
2
3
<!-- A skeleton JBoss MBean service descriptor DTD. This cannot be used in
4
general to validate a jboss-service.xml descriptor due to the fact that the
5
'attribute' element allows ANY content.
6
7
$Id: jboss-service_4_0.dtd,v 1.1.2.1 2007/03/26 09:55:00 lkotouc Exp $
8
9
DOCTYPE server
10
    PUBLIC "-//JBoss//DTD MBean Service 4.0//EN"
11
    "http://www.jboss.org/j2ee/dtd/jboss-service_4_0.dtd"
12
-->
13
<!-- The server element is the root element.
14
-->
15
<!ELEMENT server (loader-repository? , local-directory* , classpath* , mbean*)>
16
17
<!-- The loader-repository specifies the name of the UnifiedLoaderRepository
18
   MBean to use for the ear to provide ear level scoping of classes deployed
19
   in the ear. It is a unique JMX ObjectName string. It may also specify
20
   an arbitrary configuration by including a loader-repository-config element.
21
22
Examples:
23
   <loader-repository>jboss.test:loader=cts-cmp2v1-sar.ear</loader-repository>
24
25
   <loader-repository loaderRepositoryClass='dot.com.LoaderRepository'>
26
      dot.com:loader=unique-archive-name
27
      <loader-repository-config configParserClass='dot.com.LoaderParser'>
28
         java2ParentDelegaton=true
29
      </loader-repository-config>
30
   </loader-repository>
31
-->
32
<!ELEMENT loader-repository (#PCDATA | loader-repository-config)*>
33
34
<!-- The loaderRepositoryClass attribute gives the classname of the
35
org.jboss.mx.loading.LoaderRepository implementation.
36
-->
37
<!ATTLIST loader-repository loaderRepositoryClass CDATA  #IMPLIED>
38
39
<!-- The loader-repository-config element specifies any arbitrary configuration
40
fragment for use in configuring the loader-repository instance. The actual
41
content of this element is specific to the loaderRepositoryClass and the
42
code parsing the element.
43
-->
44
<!ELEMENT loader-repository-config (#PCDATA)>
45
46
<!-- The configParserClass attribute gives the classname of the
47
org.jboss.mx.loading.LoaderRepositoryFactory.LoaderRepositoryConfigParser
48
implementation to use to parse the loader-repository-config content.
49
-->
50
<!ATTLIST loader-repository-config configParserClass CDATA  #IMPLIED>
51
52
<!-- A local-directory element specifies that portions of the sar are to be unjard into the data
53
directory of the server configuration.
54
-->
55
<!ELEMENT local-directory EMPTY>
56
57
<!-- The optional path attribute gives the prefix of the sar entries that should be copied
58
into the data directory. If it is not specified the entire sar contents will be placed into
59
the data directory.
60
-->
61
<!ATTLIST local-directory path CDATA  #IMPLIED>
62
63
<!-- A classpath element specifies a location which will be included in the services
64
deployment classpath.
65
-->
66
<!ELEMENT classpath EMPTY>
67
68
<!-- The codebase attribute specifies the base URL from which the jars or classes
69
are loaded from. If the codebase is '.' then it is equal to the mbean deployment URL.
70
Otherwise, it is resolved as a path spec relative to the serverHomeURL (e.g., file:/jboss-3.2.0)
71
using the URL ctor URL(serverHomeURL, codebase)
72
73
Examples:
74
75
   <classpath codebase='.' archives='util.jar' />
76
   <classpath codebase='http://classloader.dot.com' archives='*' />
77
   <classpath codebase="lib" archives="*"/>
78
-->
79
<!ATTLIST classpath codebase CDATA  #REQUIRED>
80
81
<!-- The archives attribute specifies either the '*' wildcard to indicate all contents of the
82
codebase should be included, or a comma seperated list of the jars to include.
83
-->
84
<!ATTLIST classpath archives CDATA  #IMPLIED>
85
86
<!-- The mbean element defines a JBoss MBean service. This includes the
87
mbean class, attributes and dependencies.
88
-->
89
<!ELEMENT mbean (constructor? , xmbean? , attribute* , depends* , depends-list*)>
90
91
<!-- The code attributes gives the fully qualified name of the MBean
92
implementation class.
93
-->
94
<!ATTLIST mbean code      CDATA  #REQUIRED>
95
96
<!-- The name attribute gives the JMX ObjectName string to use when registering
97
the MBean. This must be a unique and valid JMX name.
98
-->
99
<!ATTLIST mbean name      CDATA  #REQUIRED>
100
101
<!-- The optional interface attribute gives the full qualified name of the class
102
uses to construct the management interface of the mbean. In absence of it an interface
103
with the name ending by MBean will be looked in the implementation class. When used
104
this interface is defined explicitely.
105
-->
106
<!ATTLIST mbean interface CDATA  #IMPLIED>
107
108
<!-- The xmbean-dd attribute defines the path to the JBoss XMBean descriptor. This
109
is an xml document conforming to:
110
111
<!DOCTYPE mbean PUBLIC
112
      "-//JBoss//DTD JBOSS XMBEAN 1.0//EN"
113
      "http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_0.dtd">
114
115
If the descriptor is embedded via a nested xmbean element, the xmbean-dd attribute
116
must be given as an empty string.
117
118
Example:
119
	<mbean code="org.jboss.test.jmx.xmbean.User"
120
		name="jboss.test:service=xmbean-user"
121
		xmbean-dd="META-INF/org/jboss/test/jmx/xmbean/User.xml" />
122
-->
123
<!ATTLIST mbean xmbean-dd CDATA  #IMPLIED>
124
125
<!-- The optional xmbean-code attribute specifies the ModelMBean implementation class
126
to use. This defaults to org.jboss.mx.modelmbean.XMBean.
127
-->
128
<!ATTLIST mbean xmbean-code CDATA  #IMPLIED>
129
130
<!-- The xmbean element specifies a nested JBoss XMBean descriptor fragment. Its
131
supported content model is the same as the mbean element of the jboss_xmbean_1_0.dtd
132
133
Example:
134
	<mbean code="org.jboss.test.jmx.xmbean.User"
135
		name="jboss.test:service=xmbean-user"
136
		xmbean-dd="">
137
		<xmbean>
138
			...
139
		</xmbean>
140
	</mbean>
141
-->
142
<!ELEMENT xmbean ANY>
143
144
<!-- The constructor element defines a non-default constructor to use when
145
instantiating the mbean.
146
-->
147
<!ELEMENT constructor (arg*)>
148
149
<!-- The arg element specify the constructor arguments in the order of the
150
ctor signature. Each arg has a type and value attribute.
151
-->
152
<!ELEMENT arg EMPTY>
153
154
<!-- The type attribute gives the type of the argument as defined in the
155
ctor signature. If not defined java.lang.String is assumed.
156
-->
157
<!ATTLIST arg type  CDATA  #IMPLIED>
158
159
<!-- The value attribute provides the string representation of the ctor
160
argument. It is converted from a string to type using Java PropertyEditor or a
161
ctor taking a single string as its argument.
162
-->
163
<!ATTLIST arg value CDATA  #REQUIRED>
164
165
<!-- The attribute element specifies the initial value for a management attribute of
166
the enclosing mbean. Typically the value of the attribute element is the string
167
representation of the attribute, but it can be an arbitrary xml fragment that is
168
parsed by the mbean.
169
-->
170
<!ELEMENT attribute ANY>
171
172
<!-- The required name attribute gives the name of the attribute. This is the
173
name exposed by the mbean to the MBeanServer for the attribute.
174
-->
175
<!ATTLIST attribute name CDATA  #REQUIRED>
176
177
<!-- The optional replace attribute indicates whether references of the form ${x}
178
in the attribute element content should be replaced with the corresponding
179
System.getProperty(x) value.
180
-->
181
<!ATTLIST attribute replace (true | false) 'true'>
182
<!-- The optional trim attribute specifies whether the attribute element content should
183
be trimmed of whitespace.
184
-->
185
<!ATTLIST attribute trim (true | false) 'true'>
186
187
<!-- The attributeClass attribute specifies that type of object that
188
should be created. This is needed for non-concreate attribute types
189
like interfaces and abstract classes.
190
-->
191
<!ATTLIST attribute attributeClass CDATA  #IMPLIED>
192
193
<!-- The serialDataType defines the how the content of the attribute
194
element is interpretted by the ServiceConfigurator. The possible values
195
are:
196
   + text: the content is treated as the string representation of the
197
   attribute value. It will be mapped to the attribute using the PropertyEditor
198
   registered for the attribute type.
199
   + javaBean: the content is a collection of property elements.
200
   + jbxb: the content is an xml element from a namespace with an associated
201
      xml schema that can be unmarshalled using the JBossXB framework.
202
-->
203
<!ATTLIST attribute serialDataType (text | javaBean | jbxb) 'text'>
204
205
<!-- The property element is used to describe the JavaBean properties of
206
an attribute when the attribute element serialDataType is javaBean.
207
-->
208
<!ELEMENT property (#PCDATA)>
209
<!-- The required name attribute gives the name of the property. This is the
210
name of a JavaBean property for the attribute type.
211
-->
212
<!ATTLIST property name CDATA #REQUIRED>
213
214
<!-- The depends element specifies a JMX ObjectName string for an mbean
215
on which the enclosing mbean depends.
216
217
Example:
218
   <mbean code="myBean" name="domain:name=x">
219
      <depends optional-attribute-name="yName">domain:name=y</depends>
220
   </mbean>
221
222
   <mbean code="myBean" name="domain:name=x">
223
      <depends optional-attribute-name="anonName">
224
         <mbean code="nestedBean" name="domain:name=x.y">
225
         ...
226
         </mbean>
227
      </depends>
228
   </mbean>
229
-->
230
<!ELEMENT depends (#PCDATA | mbean)*>
231
232
<!-- The optional-attribute-name attribute specifies the attribute name
233
which should be populated with the JMX ObjectName of the depends element.
234
This allows an mbean to have access to the name of the mbean on which
235
it depends.
236
-->
237
<!ATTLIST depends optional-attribute-name CDATA  #IMPLIED>
238
239
<!-- The proxy-type attribute specifies the interface name
240
that should be exposed on an MBeanProxy pointing at the dependent
241
MBean, specified by the JMX ObjectName.
242
243
The special value proxy-type="attribute" will use the
244
class declared in the MBeanAttributeInfo as the interface
245
for the MBeanProxy.
246
247
Example:
248
   <mbean code="org.jboss.example.Helper" name="domain:name=helper"/>
249
250
   <mbean code="myBean" name="domain:name=x">
251
      <depends optional-attribute-name="Helper"
252
               proxy-type="org.jboss.example.HelperMBean"
253
      >domain:name=helper</depends>
254
   </mbean>
255
256
   <mbean code="myBean" name="domain:name=x">
257
      <depends optional-attribute-name="Helper"
258
               proxy-type="attribute"
259
      >domain:name=helper</depends>
260
   </mbean>
261
-->
262
<!ATTLIST depends proxy-type CDATA  #IMPLIED>
263
264
<!-- The depends-list element specifies a series of JMX ObjectName
265
strings of mbeans on which the enclosing mbean depends.
266
267
Example:
268
   <mbean code="myBean" name="domain:name=x">
269
      <depends-list optional-attribute-name="myObjectNameList">
270
         <depends-list-element>domain:name=y</depends-list-element>
271
         <depends-list-element>domain:name=z</depends-list-element>
272
      </depends-list>
273
   </mbean>
274
-->
275
<!ELEMENT depends-list (depends-list-element)+>
276
277
<!-- The optional-attribute-name attribute specifies the attribute name
278
which should be populated with a java.util.List that contains the JMX
279
ObjectName(s) of the depends-list elements. This allows an mbean to have
280
access to the names of the mbeans on which it depends.
281
-->
282
<!ATTLIST depends-list optional-attribute-name CDATA  #IMPLIED>
283
284
<!-- The depends-list-element element specifies a JMX ObjectName string
285
for an mbean on which the enclosing mbean depends.
286
-->
287
<!ELEMENT depends-list-element (#PCDATA | mbean)*>
(-)serverplugins/sun/appsrv81/nbproject/project.xml (+1 lines)
Lines 148-153 Link Here
148
                    <compile-dependency/>
148
                    <compile-dependency/>
149
                    <run-dependency>
149
                    <run-dependency>
150
                        <release-version>4</release-version>
150
                        <release-version>4</release-version>
151
                        <specification-version>1.25</specification-version>
151
                    </run-dependency>
152
                    </run-dependency>
152
                </dependency>
153
                </dependency>
153
                <dependency>
154
                <dependency>
(-)serverplugins/sun/appsrv81/src/org/netbeans/modules/j2ee/sun/ide/j2ee/ModuleConfigurationImpl.java (+14 lines)
Lines 210-214 Link Here
210
                new UnsupportedOperationException());
210
                new UnsupportedOperationException());
211
    }
211
    }
212
212
213
    public void bindDatasourceReference(String jndiName, String dsJNDIName) throws ConfigurationException {
214
    }
215
216
    public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, String jndiName, String dsJNDIName) throws ConfigurationException {
217
    }
218
219
    public String findDatasourceJndiName(String jndiName) throws ConfigurationException {
220
        return null;
221
    }
222
223
    public String findDatasourceJndiNameForEjb(String ejbName, String jndiName) throws ConfigurationException {
224
        return null;
225
    }
226
213
}
227
}
214
228
(-)tomcatint/tomcat5/nbproject/project.xml (-1 / +1 lines)
Lines 112-118 Link Here
112
                    <compile-dependency/>
112
                    <compile-dependency/>
113
                    <run-dependency>
113
                    <run-dependency>
114
                        <release-version>4</release-version>
114
                        <release-version>4</release-version>
115
                        <specification-version>1.24</specification-version>
115
                        <specification-version>1.25</specification-version>
116
                    </run-dependency>
116
                    </run-dependency>
117
                </dependency>
117
                </dependency>
118
                <dependency>
118
                <dependency>
(-)tomcatint/tomcat5/src/org/netbeans/modules/tomcat5/config/TomcatModuleConfiguration.java (+18 lines)
Lines 612-617 Link Here
612
        else if (contextPath.indexOf("//")>=0) correct=false; //NOI18N
612
        else if (contextPath.indexOf("//")>=0) correct=false; //NOI18N
613
        return correct;
613
        return correct;
614
    }
614
    }
615
616
    public void bindDatasourceReference(String referenceName, String jndiName) throws ConfigurationException {
617
        // TODO implement
618
    }
619
620
    public void bindDatasourceReferenceForEjb(String ejbName, String ejbType, String referenceName, String jndiName) throws ConfigurationException {
621
        // TODO implement
622
    }
623
624
    public String findDatasourceJndiName(String referenceName) throws ConfigurationException {
625
        // TODO implement
626
        return null;
627
    }
628
629
    public String findDatasourceJndiNameForEjb(String ejbName, String referenceName) throws ConfigurationException {
630
        // TODO implement
631
        return null;
632
    }
615
    
633
    
616
    // private helper interface -----------------------------------------------
634
    // private helper interface -----------------------------------------------
617
     
635
     
(-)j2ee/ejbcore/nbproject/project.xml (-1 / +9 lines)
Lines 176-182 Link Here
176
                    <compile-dependency/>
176
                    <compile-dependency/>
177
                    <run-dependency>
177
                    <run-dependency>
178
                        <release-version>4</release-version>
178
                        <release-version>4</release-version>
179
                        <specification-version>1.23</specification-version>
179
                        <specification-version>1.25</specification-version>
180
                    </run-dependency>
180
                    </run-dependency>
181
                </dependency>
181
                </dependency>
182
                <dependency>
182
                <dependency>
Lines 366-371 Link Here
366
                    <compile-dependency/>
366
                    <compile-dependency/>
367
                    <run-dependency>
367
                    <run-dependency>
368
                        <specification-version>6.2</specification-version>
368
                        <specification-version>6.2</specification-version>
369
                    </run-dependency>
370
                </dependency>
371
                <dependency>
372
                    <code-name-base>org.netbeans.api.web.webmodule</code-name-base>
373
                    <build-prerequisite/>
374
                    <compile-dependency/>
375
                    <run-dependency>
376
                        <specification-version>1.8</specification-version>
369
                    </run-dependency>
377
                    </run-dependency>
370
                </dependency>
378
                </dependency>
371
            </module-dependencies>
379
            </module-dependencies>
(-)j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/SendJMSGenerator.java (-1 / +109 lines)
Lines 40-45 Link Here
40
import org.netbeans.modules.j2ee.common.source.AbstractTask;
40
import org.netbeans.modules.j2ee.common.source.AbstractTask;
41
import org.netbeans.modules.j2ee.dd.api.common.MessageDestinationRef;
41
import org.netbeans.modules.j2ee.dd.api.common.MessageDestinationRef;
42
import org.netbeans.modules.j2ee.dd.api.common.ResourceRef;
42
import org.netbeans.modules.j2ee.dd.api.common.ResourceRef;
43
import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
44
import org.netbeans.modules.j2ee.dd.api.ejb.Ejb;
45
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
46
import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
47
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
48
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
49
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
50
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
43
import org.netbeans.modules.j2ee.ejbcore.Utils;
51
import org.netbeans.modules.j2ee.ejbcore.Utils;
44
import org.netbeans.modules.j2ee.ejbcore._RetoucheUtil;
52
import org.netbeans.modules.j2ee.ejbcore._RetoucheUtil;
45
import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres.JMSDestination;
53
import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres.JMSDestination;
Lines 61-67 Link Here
61
        this.jmsDestination = jmsDestination;
69
        this.jmsDestination = jmsDestination;
62
    }
70
    }
63
    
71
    
64
    public void genMethods(EnterpriseReferenceContainer container, final String className, FileObject fileObject, ServiceLocatorStrategy slStrategy) throws IOException {
72
    public void genMethods(
73
            EnterpriseReferenceContainer container, 
74
            final String className, 
75
            FileObject fileObject, 
76
            ServiceLocatorStrategy slStrategy,
77
            J2eeModuleProvider j2eeModuleProvider,
78
            MessageDestination dest) throws IOException {
79
        
65
        JavaSource javaSource = JavaSource.forFileObject(fileObject);
80
        JavaSource javaSource = JavaSource.forFileObject(fileObject);
66
        final boolean[] isInjectionTarget = new boolean[1];
81
        final boolean[] isInjectionTarget = new boolean[1];
67
        javaSource.runUserActionTask(new AbstractTask<CompilationController>() {
82
        javaSource.runUserActionTask(new AbstractTask<CompilationController>() {
Lines 89-95 Link Here
89
        String sendMethodName = createSendMethod(fileObject, className, jmsDestination.getDestination());
104
        String sendMethodName = createSendMethod(fileObject, className, jmsDestination.getDestination());
90
        createJMSProducer(fileObject, className, factoryName, connectionFactoryFieldName, destinationName,
105
        createJMSProducer(fileObject, className, factoryName, connectionFactoryFieldName, destinationName,
91
                destinationFieldName,sendMethodName, slStrategy);
106
                destinationFieldName,sendMethodName, slStrategy);
107
        
108
if (System.getProperties().getProperty("resource-api-redesign") != null) {
109
110
    if (dest != null) {
111
        try {
112
            if (j2eeModuleProvider.getJ2eeModule().getModuleType().equals(J2eeModule.WAR)) {
113
                //in the current implementation, reference name is the same as the destination name...
114
                j2eeModuleProvider.getConfigSupport().bindMessageDestinationReference(
115
                        dest.getName(), factoryName, dest.getName(), dest.getType());
116
            }
117
            else
118
            if (j2eeModuleProvider.getJ2eeModule().getModuleType().equals(J2eeModule.EJB)) {
119
                //in the current implementation, reference name is the same as the destination name...
120
                bindMessageDestinationReferenceForEjb(j2eeModuleProvider, fileObject, className, 
121
                        dest.getName(), factoryName, dest.getName(), dest.getType());
122
            }
123
        }
124
        catch (ConfigurationException ce) {
125
        }
126
    }
127
}
128
129
    }
130
131
private void bindMessageDestinationReferenceForEjb(J2eeModuleProvider j2eeModuleProvider, 
132
        FileObject fileObject, String className, 
133
        String referenceName, String connectionFactoryName,
134
        String destName, MessageDestination.Type destType) throws ConfigurationException {
135
136
    EjbJar dd = null;
137
    try {
138
        dd = findDDRoot(fileObject);
139
    }
140
    catch (IOException ioe) {
141
        // TODO
142
    }
143
    if (dd == null) {
144
        return;
145
    }
146
    
147
    EnterpriseBeans beans = dd.getEnterpriseBeans();
148
    if (beans == null) {
149
        return;
92
    }
150
    }
151
152
    String ejbName = getEjbName(beans, className);
153
    if (ejbName == null) {
154
        return;
155
    }
156
157
    String ejbType = getEjbType(beans, className);
158
    if (ejbType == null) {
159
        return;
160
    }
161
    
162
    j2eeModuleProvider.getConfigSupport().bindMessageDestinationReferenceForEjb(
163
            ejbName, ejbType, referenceName, connectionFactoryName, destName, destType);
164
}        
165
      
166
private EjbJar findDDRoot(FileObject fileObject) throws IOException {
167
    org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbJar = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(fileObject);
168
    assert ejbJar != null;
169
    return DDProvider.getDefault().getMergedDDRoot(ejbJar.getMetadataUnit());
170
}
171
172
private String getEjbName(EnterpriseBeans beans, String className) {
173
    Ejb ejb = (Ejb) beans.findBeanByName(EnterpriseBeans.SESSION, Ejb.EJB_CLASS, className);
174
    if (ejb == null) {
175
        ejb = (Ejb) beans.findBeanByName(EnterpriseBeans.ENTITY, Ejb.EJB_CLASS, className);
176
    }
177
    if (ejb == null) {
178
        ejb = (Ejb) beans.findBeanByName(EnterpriseBeans.MESSAGE_DRIVEN, Ejb.EJB_CLASS, className);
179
    }
180
181
    return ejb.getEjbName();
182
}
183
184
private String getEjbType(EnterpriseBeans beans, String className) {
185
    String type = null;
186
187
    if (beans.findBeanByName(EnterpriseBeans.SESSION, Ejb.EJB_CLASS, className) != null) {
188
        type = EnterpriseBeans.SESSION;
189
    }
190
    else
191
    if (beans.findBeanByName(EnterpriseBeans.ENTITY, Ejb.EJB_CLASS, className) != null) {
192
        type = EnterpriseBeans.ENTITY;
193
    }
194
    else
195
    if (beans.findBeanByName(EnterpriseBeans.MESSAGE_DRIVEN, Ejb.EJB_CLASS, className) != null) {
196
        type = EnterpriseBeans.MESSAGE_DRIVEN;
197
    }
198
199
    return type;
200
}
93
    
201
    
94
    private String generateConnectionFactoryReference(EnterpriseReferenceContainer container, FileObject referencingFile, String referencingClass) throws IOException {
202
    private String generateConnectionFactoryReference(EnterpriseReferenceContainer container, FileObject referencingFile, String referencingClass) throws IOException {
95
        ResourceRef ref = container.createResourceRef(referencingClass);
203
        ResourceRef ref = container.createResourceRef(referencingClass);
(-)j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/UseDatabaseGenerator.java (-3 / +109 lines)
Lines 13-19 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
19
Lines 37-43 Link Here
37
import org.netbeans.modules.j2ee.common.queries.api.InjectionTargetQuery;
37
import org.netbeans.modules.j2ee.common.queries.api.InjectionTargetQuery;
38
import org.netbeans.modules.j2ee.common.source.AbstractTask;
38
import org.netbeans.modules.j2ee.common.source.AbstractTask;
39
import org.netbeans.modules.j2ee.dd.api.common.ResourceRef;
39
import org.netbeans.modules.j2ee.dd.api.common.ResourceRef;
40
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
41
import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
42
import org.netbeans.modules.j2ee.dd.api.ejb.Ejb;
43
import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
44
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
40
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
45
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
46
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
47
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
41
import org.netbeans.modules.j2ee.ejbcore.Utils;
48
import org.netbeans.modules.j2ee.ejbcore.Utils;
42
import org.netbeans.modules.j2ee.ejbcore._RetoucheUtil;
49
import org.netbeans.modules.j2ee.ejbcore._RetoucheUtil;
43
import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres.ServiceLocatorStrategy;
50
import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres.ServiceLocatorStrategy;
Lines 52-59 Link Here
52
    public UseDatabaseGenerator() {
59
    public UseDatabaseGenerator() {
53
    }
60
    }
54
61
55
    public void generate(final FileObject fileObject, final ElementHandle<TypeElement> elementHandle, final Datasource datasource, 
62
    public void generate(final FileObject fileObject, final ElementHandle<TypeElement> elementHandle, 
56
            final boolean createServerResources, String serviceLocator) throws IOException {
63
                         final J2eeModuleProvider j2eeModuleProvider, final String datasourceReferenceName, 
64
                         final Datasource datasource, final boolean createServerResources, String serviceLocator) 
65
                         throws IOException, ConfigurationException
66
    {
57
        Project project = FileOwnerQuery.getOwner(fileObject);
67
        Project project = FileOwnerQuery.getOwner(fileObject);
58
        ServiceLocatorStrategy serviceLocatorStrategy = (serviceLocator == null) ? null : 
68
        ServiceLocatorStrategy serviceLocatorStrategy = (serviceLocator == null) ? null : 
59
            ServiceLocatorStrategy.create(project, fileObject, serviceLocator);
69
            ServiceLocatorStrategy.create(project, fileObject, serviceLocator);
Lines 73-81 Link Here
73
                generateLookupMethod(fileObject, className, jndiName, serviceLocatorStrategy);
83
                generateLookupMethod(fileObject, className, jndiName, serviceLocatorStrategy);
74
            }
84
            }
75
        }
85
        }
86
        
87
if (System.getProperties().getProperty("resource-api-redesign") != null) {
88
    J2eeModule module = j2eeModuleProvider.getJ2eeModule();
89
    if (isWebModule(module)) {
90
        bindDataSourceReference(j2eeModuleProvider, datasourceReferenceName, datasource);
91
    }
92
    else if (isEjbModule(module)) {
93
        bindDataSourceReferenceForEjb(j2eeModuleProvider, datasourceReferenceName, datasource, fileObject, elementHandle);
94
    }
95
}
96
        
76
        if (serviceLocator != null) {
97
        if (serviceLocator != null) {
77
            erc.setServiceLocatorName(serviceLocator);
98
            erc.setServiceLocatorName(serviceLocator);
78
        }
99
        }
100
    }
101
    
102
    private void bindDataSourceReference(J2eeModuleProvider j2eeModuleProvider, String dsRefName, Datasource datasource) 
103
    throws ConfigurationException {
104
105
        String dsJndiName = datasource.getJndiName();
106
        j2eeModuleProvider.getConfigSupport().bindDatasourceReference(dsRefName, dsJndiName);
107
    }
108
    
109
    private void bindDataSourceReferenceForEjb(J2eeModuleProvider j2eeModuleProvider, String dsRefName, Datasource datasource,
110
            FileObject fileObject, ElementHandle<TypeElement> elementHandle) throws ConfigurationException {
111
112
        String dsJndiName = datasource.getJndiName();
113
114
        EjbJar dd = null;
115
        try {
116
            dd = findDDRoot(fileObject);
117
        }
118
        catch (IOException ioe) {
119
            // TODO
120
        }
121
        if (dd == null) {
122
            return;
123
        }
124
        
125
        EnterpriseBeans beans = dd.getEnterpriseBeans();
126
        if (beans == null) {
127
            return;
128
        }
129
        
130
        String ejbName = getEjbName(beans, elementHandle.getQualifiedName());
131
        if (ejbName == null) {
132
            return;
133
        }
134
        
135
        String ejbType = getEjbType(beans, elementHandle.getQualifiedName());
136
        if (ejbType == null) {
137
            return;
138
        }
139
        
140
        j2eeModuleProvider.getConfigSupport().bindDatasourceReferenceForEjb(ejbName, ejbType, dsRefName, dsJndiName);
141
    }
142
    
143
    private EjbJar findDDRoot(FileObject fileObject) throws IOException {
144
        org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbJar = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(fileObject);
145
        assert ejbJar != null;
146
        return DDProvider.getDefault().getMergedDDRoot(ejbJar.getMetadataUnit());
147
    }
148
    
149
    private boolean isWebModule(J2eeModule module) {
150
        return module.getModuleType().equals(J2eeModule.WAR);
151
    }
152
    
153
    private boolean isEjbModule(J2eeModule module) {
154
        return module.getModuleType().equals(J2eeModule.EJB);
155
    }
156
    
157
    private String getEjbName(EnterpriseBeans beans, String className) {
158
        Ejb ejb = (Ejb) beans.findBeanByName(EnterpriseBeans.SESSION, Ejb.EJB_CLASS, className);
159
        if (ejb == null) {
160
            ejb = (Ejb) beans.findBeanByName(EnterpriseBeans.ENTITY, Ejb.EJB_CLASS, className);
161
        }
162
        if (ejb == null) {
163
            ejb = (Ejb) beans.findBeanByName(EnterpriseBeans.MESSAGE_DRIVEN, Ejb.EJB_CLASS, className);
164
        }
165
166
        return ejb.getEjbName();
167
    }
168
    
169
    private String getEjbType(EnterpriseBeans beans, String className) {
170
        String type = null;
171
        
172
        if (beans.findBeanByName(EnterpriseBeans.SESSION, Ejb.EJB_CLASS, className) != null) {
173
            type = EnterpriseBeans.SESSION;
174
        }
175
        else
176
        if (beans.findBeanByName(EnterpriseBeans.ENTITY, Ejb.EJB_CLASS, className) != null) {
177
            type = EnterpriseBeans.ENTITY;
178
        }
179
        else
180
        if (beans.findBeanByName(EnterpriseBeans.MESSAGE_DRIVEN, Ejb.EJB_CLASS, className) != null) {
181
            type = EnterpriseBeans.MESSAGE_DRIVEN;
182
        }
183
184
        return type;
79
    }
185
    }
80
    
186
    
81
    private String generateJNDILookup(String jndiName, EnterpriseReferenceContainer enterpriseReferenceContainer, 
187
    private String generateJNDILookup(String jndiName, EnterpriseReferenceContainer enterpriseReferenceContainer, 
(-)j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/MessageGenerator.java (+17 lines)
Lines 106-111 Link Here
106
                    ErrorManager.getDefault().notify(ex);
106
                    ErrorManager.getDefault().notify(ex);
107
                }
107
                }
108
            }
108
            }
109
110
if (System.getProperties().getProperty("resource-api-redesign") != null) {
111
    try {
112
        Project project = FileOwnerQuery.getOwner(pkg);
113
        J2eeModuleProvider j2eeModuleProvider = (J2eeModuleProvider) project.getLookup().lookup(J2eeModuleProvider.class);
114
        if (isQueue) {
115
            j2eeModuleProvider.getConfigSupport().bindMdbToMessageDestination(ejbName, "MyQueue", org.netbeans.modules.j2ee.deployment.common.api.MessageDestination.Type.QUEUE);
116
        }
117
        else {
118
            j2eeModuleProvider.getConfigSupport().bindMdbToMessageDestination(ejbName, "MyTopic", org.netbeans.modules.j2ee.deployment.common.api.MessageDestination.Type.TOPIC);
119
        }
120
    }
121
    catch (ConfigurationException ce) {
122
        // TODO inform user
123
    }
124
}        
125
            
109
        }
126
        }
110
        return resultFileObject;
127
        return resultFileObject;
111
    }
128
    }
(-)j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/mdb/MessageEJBWizard.java (-1 / +25 lines)
Lines 13-25 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
19
20
package org.netbeans.modules.j2ee.ejbcore.ejb.wizard.mdb;
20
package org.netbeans.modules.j2ee.ejbcore.ejb.wizard.mdb;
21
21
22
import java.io.IOException;
22
import java.io.IOException;
23
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
23
import org.netbeans.modules.j2ee.ejbcore.api.codegeneration.MessageGenerator;
24
import org.netbeans.modules.j2ee.ejbcore.api.codegeneration.MessageGenerator;
24
import java.util.Collections;
25
import java.util.Collections;
25
import java.util.NoSuchElementException;
26
import java.util.NoSuchElementException;
Lines 34-39 Link Here
34
import org.netbeans.spi.project.ui.templates.support.Templates;
35
import org.netbeans.spi.project.ui.templates.support.Templates;
35
import org.openide.filesystems.FileObject;
36
import org.openide.filesystems.FileObject;
36
import org.netbeans.modules.j2ee.common.Util;
37
import org.netbeans.modules.j2ee.common.Util;
38
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
39
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
37
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
40
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
38
import org.netbeans.modules.j2ee.ejbcore.Utils;
41
import org.netbeans.modules.j2ee.ejbcore.Utils;
39
import org.openide.WizardDescriptor;
42
import org.openide.WizardDescriptor;
Lines 73-78 Link Here
73
        Util.hideLabelAndLabelFor(jComponent, NbBundle.getMessage(MessageEJBWizard.class, "LBL_JavaTargetChooserPanelGUI_CreatedFile_Label"));
76
        Util.hideLabelAndLabelFor(jComponent, NbBundle.getMessage(MessageEJBWizard.class, "LBL_JavaTargetChooserPanelGUI_CreatedFile_Label"));
74
        panels = new WizardDescriptor.Panel[] {wizardPanel};
77
        panels = new WizardDescriptor.Panel[] {wizardPanel};
75
        Utils.mergeSteps(wiz, panels, SESSION_STEPS);
78
        Utils.mergeSteps(wiz, panels, SESSION_STEPS);
79
        
80
if (System.getProperties().getProperty("resource-api-redesign") != null) {
81
    J2eeModuleProvider provider = project.getLookup().lookup(J2eeModuleProvider.class);
82
    try {
83
        Set<MessageDestination> moduleDestinations = provider.getConfigSupport().getMessageDestinations();
84
        for (MessageDestination md : moduleDestinations) {
85
            System.out.println(md.getName() + " ~ " + md.getType());
86
        }
87
        if (provider.getConfigSupport().supportsCreateMessageDestination()) {
88
            MessageDestination dest = provider.getConfigSupport().createMessageDestination("TestMsgDest01", MessageDestination.Type.TOPIC);
89
        }
90
        Set<MessageDestination> serverDestinations = provider.getConfigSupport().getServerMessageDestinations();
91
        for (MessageDestination md : serverDestinations) {
92
            System.out.println(md.getName() + " ~ " + md.getType());
93
        }
94
    }
95
    catch (ConfigurationException ce) {
96
97
    }
98
}
99
76
    }
100
    }
77
101
78
    public Set instantiate() throws IOException {
102
    public Set instantiate() throws IOException {
(-)j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/MessageDestinationPanel.java (+56 lines)
Lines 26-35 Link Here
26
import java.beans.PropertyChangeListener;
26
import java.beans.PropertyChangeListener;
27
import java.io.IOException;
27
import java.io.IOException;
28
import java.util.Iterator;
28
import java.util.Iterator;
29
import java.util.LinkedList;
29
import java.util.List;
30
import java.util.List;
30
import javax.swing.DefaultComboBoxModel;
31
import javax.swing.DefaultComboBoxModel;
31
import javax.swing.JButton;
32
import javax.swing.JButton;
32
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
33
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
34
import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
35
import org.netbeans.modules.j2ee.dd.api.ejb.MessageDriven;
36
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
37
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
38
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
33
import org.openide.DialogDisplayer;
39
import org.openide.DialogDisplayer;
34
import org.openide.NotifyDescriptor;
40
import org.openide.NotifyDescriptor;
35
41
Lines 45-50 Link Here
45
    private DefaultComboBoxModel destinationModel;
51
    private DefaultComboBoxModel destinationModel;
46
    private final ServiceLocatorStrategyPanel slPanel;
52
    private final ServiceLocatorStrategyPanel slPanel;
47
    
53
    
54
private MessageDestination dest = null;
55
56
public MessageDestination getDestination() {
57
    return dest;
58
}
59
    
48
    /** Creates new form MessageDestinationPanel */
60
    /** Creates new form MessageDestinationPanel */
49
    public MessageDestinationPanel(final JButton okButton, String lastLocator) {
61
    public MessageDestinationPanel(final JButton okButton, String lastLocator) {
50
        initComponents();
62
        initComponents();
Lines 103-108 Link Here
103
    }
115
    }
104
     
116
     
105
    private void populateEjbDestinationCombo(Object selectedItem) throws IOException {
117
    private void populateEjbDestinationCombo(Object selectedItem) throws IOException {
118
119
if (System.getProperties().getProperty("resource-api-redesign") != null) {
120
    List<String> names = getMdbNames(selectedItem);
121
    for (String name : names) {
122
        System.out.println(name);
123
    }
124
    if (names.size() > 0) {
125
        String mdbName = names.get(0);
126
        J2eeModuleProvider j2eeModuleProvider = controller.getJ2eeModuleProvider(selectedItem);
127
        try {
128
            String destName = j2eeModuleProvider.getConfigSupport().findMessageDestinationName(mdbName);
129
            if (destName != null) {
130
                dest = j2eeModuleProvider.getConfigSupport().findMessageDestination(destName);
131
            }
132
        }
133
        catch (ConfigurationException ce) {}
134
    }
135
}
136
106
        EjbJar ejbJar = controller.getEjbJar(selectedItem);
137
        EjbJar ejbJar = controller.getEjbJar(selectedItem);
107
        if (ejbJar != null) {
138
        if (ejbJar != null) {
108
            List list = controller.extractEjbProjectDestinations(ejbJar, selectedItem);
139
            List list = controller.extractEjbProjectDestinations(ejbJar, selectedItem);
Lines 112-117 Link Here
112
            }
143
            }
113
        }
144
        }
114
    }
145
    }
146
    
147
    private List<String> getMdbNames(Object projectItem) throws IOException {
148
        
149
        List<String> names = new LinkedList<String>();
150
        
151
        EjbJar ejbJar = controller.getEjbJar(projectItem);
152
        if (ejbJar == null) {
153
            return names;
154
        }
155
        
156
        EnterpriseBeans eb = ejbJar.getEnterpriseBeans();
157
        if (eb == null) {
158
            return names;
159
        }
160
        
161
        MessageDriven[] mdbs = eb.getMessageDriven();
162
        for (MessageDriven mdb : mdbs) {
163
            if (mdb.getEjbName() != null) {
164
                names.add(mdb.getEjbName());
165
            }
166
        }
167
        
168
        return names;
169
    }
170
    
115
    /** This method is called from within the constructor to
171
    /** This method is called from within the constructor to
116
     * initialize the form.
172
     * initialize the form.
117
     * WARNING: Do NOT modify this code. The content of this method is
173
     * WARNING: Do NOT modify this code. The content of this method is
(-)j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/MessageDestinationPanelController.java (+6 lines)
Lines 31-36 Link Here
31
import org.netbeans.modules.j2ee.dd.api.ejb.Ejb;
31
import org.netbeans.modules.j2ee.dd.api.ejb.Ejb;
32
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
32
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
33
import org.netbeans.modules.j2ee.dd.api.ejb.MessageDriven;
33
import org.netbeans.modules.j2ee.dd.api.ejb.MessageDriven;
34
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
34
import org.openide.ErrorManager;
35
import org.openide.ErrorManager;
35
36
36
/**
37
/**
Lines 49-54 Link Here
49
            }
50
            }
50
        }
51
        }
51
        return projectViews.toArray(new ProjectView[projectViews.size()]);
52
        return projectViews.toArray(new ProjectView[projectViews.size()]);
53
    }
54
55
    public J2eeModuleProvider getJ2eeModuleProvider(Object item) {
56
        Project project = ((ProjectView) item).getProject();
57
        return project.getLookup().lookup(J2eeModuleProvider.class);
52
    }
58
    }
53
    
59
    
54
    public EjbJar getEjbJar(Object item) throws IOException {
60
    public EjbJar getEjbJar(Object item) throws IOException {
(-)j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/SendJMSMessageAction.java (-1 / +12 lines)
Lines 34-41 Link Here
34
import org.netbeans.modules.j2ee.api.ejbjar.EnterpriseReferenceContainer;
34
import org.netbeans.modules.j2ee.api.ejbjar.EnterpriseReferenceContainer;
35
import org.netbeans.modules.j2ee.common.Util;
35
import org.netbeans.modules.j2ee.common.Util;
36
import org.netbeans.modules.j2ee.common.source.AbstractTask;
36
import org.netbeans.modules.j2ee.common.source.AbstractTask;
37
import org.netbeans.modules.j2ee.dd.api.ejb.Ejb;
37
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
38
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
39
import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
38
import org.netbeans.modules.j2ee.dd.api.web.WebApp;
40
import org.netbeans.modules.j2ee.dd.api.web.WebApp;
41
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
42
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
39
import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
43
import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
40
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
44
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
41
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
45
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
Lines 111-118 Link Here
111
                        ServiceLocatorStrategy.create(enterpriseProject, srcFile, 
115
                        ServiceLocatorStrategy.create(enterpriseProject, srcFile, 
112
                                                      serviceLocator);
116
                                                      serviceLocator);
113
            }
117
            }
118
            
114
            SendJMSGenerator generator = new SendJMSGenerator(destination);
119
            SendJMSGenerator generator = new SendJMSGenerator(destination);
115
            generator.genMethods(erc, beanClass.getQualifiedName().toString(), srcFile, serviceLocatorStrategy);
120
            generator.genMethods(
121
                    erc, 
122
                    beanClass.getQualifiedName().toString(), 
123
                    srcFile, 
124
                    serviceLocatorStrategy,
125
                    enterpriseProject.getLookup().lookup(J2eeModuleProvider.class),
126
                    panel.getDestination());
116
            if (serviceLocator != null) {
127
            if (serviceLocator != null) {
117
                erc.setServiceLocatorName(serviceLocator);
128
                erc.setServiceLocatorName(serviceLocator);
118
            }
129
            }
(-)j2ee/ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/UseDatabaseAction.java (-8 / +125 lines)
Lines 13-19 Link Here
13
 * "Portions Copyrighted [year] [name of copyright owner]"
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
18
 */
19
19
Lines 22-27 Link Here
22
import java.beans.PropertyChangeEvent;
22
import java.beans.PropertyChangeEvent;
23
import java.beans.PropertyChangeListener;
23
import java.beans.PropertyChangeListener;
24
import java.io.IOException;
24
import java.io.IOException;
25
import java.util.HashMap;
26
import java.util.Map;
25
import javax.lang.model.element.ElementKind;
27
import javax.lang.model.element.ElementKind;
26
import javax.lang.model.element.TypeElement;
28
import javax.lang.model.element.TypeElement;
27
import javax.swing.Action;
29
import javax.swing.Action;
Lines 33-41 Link Here
33
import org.netbeans.api.project.Project;
35
import org.netbeans.api.project.Project;
34
import org.netbeans.modules.j2ee.api.ejbjar.EnterpriseReferenceContainer;
36
import org.netbeans.modules.j2ee.api.ejbjar.EnterpriseReferenceContainer;
35
import org.netbeans.modules.j2ee.common.source.AbstractTask;
37
import org.netbeans.modules.j2ee.common.source.AbstractTask;
38
import org.netbeans.modules.j2ee.dd.api.common.ResourceRef;
39
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
40
import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
41
import org.netbeans.modules.j2ee.dd.api.ejb.Ejb;
42
import org.netbeans.modules.j2ee.dd.api.web.WebApp;
43
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
44
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
45
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
36
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
46
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
37
import org.netbeans.modules.j2ee.ejbcore._RetoucheUtil;
47
import org.netbeans.modules.j2ee.ejbcore._RetoucheUtil;
38
import org.netbeans.modules.j2ee.ejbcore.action.UseDatabaseGenerator;
48
import org.netbeans.modules.j2ee.ejbcore.action.UseDatabaseGenerator;
49
import org.netbeans.modules.web.api.webmodule.WebModule;
39
import org.openide.DialogDescriptor;
50
import org.openide.DialogDescriptor;
40
import org.openide.DialogDisplayer;
51
import org.openide.DialogDisplayer;
41
import org.openide.ErrorManager;
52
import org.openide.ErrorManager;
Lines 97-116 Link Here
97
            }
108
            }
98
        });
109
        });
99
        selectDatabasePanel.checkDatasource();
110
        selectDatabasePanel.checkDatasource();
111
        
112
if (System.getProperties().getProperty("resource-api-redesign") != null) {
113
    try {            
114
        Map<String, Datasource> refs = getDataSourceReferences(j2eeModuleProvider, fileObject);
115
    }
116
    catch (ConfigurationException ce) {
117
        //TODO notify user
118
    }
119
}
120
String refName = "NameOfSelectedReference";
121
        
100
        Object option = DialogDisplayer.getDefault().notify(dialogDescriptor);
122
        Object option = DialogDisplayer.getDefault().notify(dialogDescriptor);
101
        if (option == NotifyDescriptor.OK_OPTION) {
123
        if (option == NotifyDescriptor.OK_OPTION) {
124
            
102
            UseDatabaseGenerator generator = new UseDatabaseGenerator();
125
            UseDatabaseGenerator generator = new UseDatabaseGenerator();
103
            generator.generate(
126
            try {
104
                    fileObject,
127
                generator.generate(
105
                    elementHandle,
128
                        fileObject,
106
                    selectDatabasePanel.getDatasource(),
129
                        elementHandle,
107
                    selectDatabasePanel.createServerResources(),
130
                        j2eeModuleProvider,
108
                    selectDatabasePanel.getServiceLocator()
131
                        refName,
109
                    );
132
                        selectDatabasePanel.getDatasource(),
133
                        selectDatabasePanel.createServerResources(),
134
                        selectDatabasePanel.getServiceLocator()
135
                        );
136
            }
137
            catch (ConfigurationException ex) {
138
                //TODO
139
            }
110
        }
140
        }
111
        return false;
141
        return false;
112
    }
142
    }
143
144
    private Map<String, Datasource> getDataSourceReferences(J2eeModuleProvider j2eeModuleProvider, FileObject fileObject) 
145
    throws ConfigurationException {
146
        
147
        HashMap<String, Datasource> references = new HashMap<String, Datasource>();
148
        
149
        if (j2eeModuleProvider.getJ2eeModule().getModuleType().equals(J2eeModule.EJB)) {
150
            EjbJar dd = findEjbDDRoot(fileObject);
151
            if (dd == null) {
152
                return references;
153
            }
154
            EnterpriseBeans beans = dd.getEnterpriseBeans();
155
            if (beans == null) {
156
                return references;
157
            }
158
            
159
            Ejb[] ejbs = beans.getEjbs();
160
            for (Ejb ejb : ejbs) {
161
                ResourceRef[] refs = ejb.getResourceRef();
162
                for (ResourceRef ref : refs) {
163
                    String refName = ref.getResRefName();
164
                    Datasource ds = findDatasourceForReferenceForEjb(j2eeModuleProvider, refName, ejb.getEjbName());
165
                    if (ds != null) {
166
                        references.put(refName, ds);
167
                        System.out.println(refName + " ~ " + ds.getUrl());
168
                    }
169
                }
170
            }
171
        }
172
        else
173
        if (j2eeModuleProvider.getJ2eeModule().getModuleType().equals(J2eeModule.WAR)) {
174
            WebApp dd = findWebDDRoot(fileObject);
175
            if (dd == null) {
176
                return references;
177
            }
178
            ResourceRef[] refs = dd.getResourceRef();
179
            for (ResourceRef ref : refs) {
180
                String refName = ref.getResRefName();
181
                Datasource ds = findDatasourceForReference(j2eeModuleProvider, refName);
182
                if (ds != null) {
183
                    references.put(refName, ds);
184
                    System.out.println(refName + " ~ " + ds.getUrl());
185
                }
186
            }
187
        }
188
        
189
        return references;
190
    }
191
192
    private Datasource findDatasourceForReference(J2eeModuleProvider j2eeModuleProvider, String referenceName) throws ConfigurationException {
193
        String jndiName = j2eeModuleProvider.getConfigSupport().findDatasourceJndiName(referenceName);
194
        if (jndiName == null) {
195
            return null;
196
        }
197
        return j2eeModuleProvider.getConfigSupport().findDatasource(jndiName);
198
    }
199
    
200
    public Datasource findDatasourceForReferenceForEjb(J2eeModuleProvider j2eeModuleProvider, String referenceName, String ejbName) throws ConfigurationException {
201
        String jndiName = j2eeModuleProvider.getConfigSupport().findDatasourceJndiNameForEjb(ejbName, referenceName);
202
        if (jndiName == null) {
203
            return null;
204
        }
205
        return j2eeModuleProvider.getConfigSupport().findDatasource(jndiName);
206
    }
113
    
207
    
208
    private EjbJar findEjbDDRoot(FileObject fileObject) throws ConfigurationException {
209
        org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbJar = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(fileObject);
210
        assert ejbJar != null;
211
        try {
212
            return org.netbeans.modules.j2ee.dd.api.ejb.DDProvider.getDefault().getMergedDDRoot(ejbJar.getMetadataUnit());
213
        }
214
        catch (IOException ioe) {
215
            String msg = NbBundle.getMessage(UseDatabaseAction.class, "ERR_CannotReadEjbDD");
216
            throw new ConfigurationException(msg, ioe);
217
        }
218
    }
219
    
220
    private WebApp findWebDDRoot(FileObject fileObject) throws ConfigurationException {
221
        WebModule mod = WebModule.getWebModule(fileObject);
222
        try {
223
            return org.netbeans.modules.j2ee.dd.api.web.DDProvider.getDefault().getMergedDDRoot(mod);
224
        }
225
        catch (IOException ioe) {
226
            String msg = NbBundle.getMessage(UseDatabaseAction.class, "ERR_CannotReadWebDD");
227
            throw new ConfigurationException(msg, ioe);
228
        }
229
    }
230
        
114
    protected boolean enable(Node[] nodes) {
231
    protected boolean enable(Node[] nodes) {
115
        if (nodes == null || nodes.length != 1) {
232
        if (nodes == null || nodes.length != 1) {
116
            return false;
233
            return false;

Return to bug 93815