~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to j2ee/ejbapi/src/org/netbeans/modules/j2ee/api/ejbjar/Car.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
package org.netbeans.modules.j2ee.api.ejbjar;
 
42
 
 
43
import org.netbeans.api.project.Project;
 
44
import org.netbeans.modules.j2ee.ejbjar.CarAccessor;
 
45
import org.netbeans.modules.j2ee.spi.ejbjar.CarImplementation;
 
46
import org.netbeans.modules.j2ee.spi.ejbjar.CarProvider;
 
47
import org.netbeans.modules.j2ee.spi.ejbjar.CarsInProject;
 
48
import org.openide.filesystems.FileObject;
 
49
import org.openide.util.Lookup;
 
50
 
 
51
/**
 
52
 * Car should be used to access properties of an Enterprise application client module.
 
53
 * <p>
 
54
 * A client may obtain a Car instance using 
 
55
 * <code>Car.getCar(fileObject)</code> static method, for any 
 
56
 * FileObject in the application client module directory structure.
 
57
 * </p>
 
58
 * <div class="nonnormative">
 
59
 * Note that the particular directory structure for application client module
 
60
 * is not guaranteed by this API.
 
61
 * </div>
 
62
 * 
 
63
 * 
 
64
 * @author Pavel Buzek
 
65
 * @author Lukas Jungmann
 
66
 */
 
67
public final class Car {
 
68
    private CarImplementation impl;
 
69
    private static final Lookup.Result<CarProvider> implementations =
 
70
        Lookup.getDefault().lookup(new Lookup.Template<CarProvider>(CarProvider.class));
 
71
    
 
72
    static  {
 
73
        CarAccessor.DEFAULT = new CarAccessor() {
 
74
            public Car createCar(CarImplementation spiEjbJar) {
 
75
                return new Car(spiEjbJar);
 
76
            }
 
77
 
 
78
            public CarImplementation getCarImplementation(Car wm) {
 
79
                return wm == null ? null : wm.impl;
 
80
            }
 
81
        };
 
82
    }
 
83
    
 
84
    private Car (CarImplementation impl) {
 
85
        if (impl == null)
 
86
            throw new IllegalArgumentException ();
 
87
        this.impl = impl;
 
88
    }
 
89
    
 
90
    /**
 
91
     * Find the Car for given file or null if the file does not belong
 
92
     * to any application client module.
 
93
     */
 
94
    public static Car getCar (FileObject f) {
 
95
        if (f == null) {
 
96
            throw new NullPointerException("Passed null to Car.getCar(FileObject)"); // NOI18N
 
97
        }
 
98
        for (CarProvider impl : implementations.allInstances()) {
 
99
            Car wm = impl.findCar (f);
 
100
            if (wm != null) {
 
101
                return wm;
 
102
            }
 
103
        }
 
104
        return null;
 
105
    }
 
106
 
 
107
    /** Find Car(s) for all application clients within a given project.
 
108
     * @return an array of Car instance (empty array if no instance are found).
 
109
     */
 
110
    public static Car[] getCars (Project project) {
 
111
        CarsInProject providers = project.getLookup().lookup(CarsInProject.class);
 
112
        if (providers != null) {
 
113
            Car jars [] = providers.getCars();
 
114
            if (jars != null) {
 
115
                return jars;
 
116
            }
 
117
        }
 
118
        return new Car[] {};
 
119
    }
 
120
    
 
121
    /** J2EE platform version - one of the constants 
 
122
     * defined in {@link org.netbeans.modules.j2ee.api.common.J2eeProjectConstants}.
 
123
     * @return J2EE platform version
 
124
     */
 
125
    public String getJ2eePlatformVersion () {
 
126
        return impl.getJ2eePlatformVersion();
 
127
    }
 
128
    
 
129
    /** Deployment descriptor (application-client.xml file) of the application client module.
 
130
     */
 
131
    public FileObject getDeploymentDescriptor () {
 
132
        return impl.getDeploymentDescriptor();
 
133
    }
 
134
 
 
135
    /** Source roots associated with the Car module.
 
136
     * <div class="nonnormative">
 
137
     * Note that not all the java source roots in the project (e.g. in a freeform project)
 
138
     * belong to the Car module.
 
139
     * </div>
 
140
     */
 
141
    public FileObject[] getJavaSources() {
 
142
        return impl.getJavaSources();
 
143
    }
 
144
    
 
145
    /** Meta-inf
 
146
     */
 
147
    public FileObject getMetaInf() {
 
148
        return impl.getMetaInf();
 
149
    }
 
150
}