KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > api > PersistenceScopes


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.persistence.api;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import org.netbeans.api.project.Project;
24 import org.netbeans.modules.j2ee.persistence.spi.PersistenceScopesImplementation;
25 import org.netbeans.modules.j2ee.persistence.spi.PersistenceScopesProvider;
26 import org.netbeans.modules.j2ee.persistenceapi.PersistenceScopesAccessor;
27
28 /**
29  * Describes a list of persistence scopes and allows listening on this list.
30  *
31  * @author Andrei Badea
32  */

33 public final class PersistenceScopes {
34
35     /**
36      * The property corresponding to {@link #getPersistenceScopes}.
37      */

38     public static final String JavaDoc PROP_PERSISTENCE_SCOPES = "persistenceScopes"; // NOI18N
39

40     private final PersistenceScopesImplementation impl;
41
42     static {
43         PersistenceScopesAccessor.DEFAULT = new PersistenceScopesAccessor() {
44             public PersistenceScopes createPersistenceScopes(PersistenceScopesImplementation impl) {
45                 return new PersistenceScopes(impl);
46             }
47         };
48     }
49
50     /**
51      * Returns an instance of <code>PersistenceScopes</code> for the given
52      * project.
53      *
54      * @return an instance of <code>PersistenceScopes</code> or null if the
55      * project doesn't provide a list of persistence scopes.
56      * @throws NullPointerException if <code>project</code> was null.
57      */

58     public static PersistenceScopes getPersistenceScopes(Project project) {
59         if (project == null) {
60             throw new NullPointerException JavaDoc("Passed null to PersistenceScopes.getPersistenceScopes(Project)"); // NOI18N
61
};
62         PersistenceScopesProvider provider = (PersistenceScopesProvider)project.getLookup().lookup(PersistenceScopesProvider.class);
63         if (provider != null) {
64             return provider.getPersistenceScopes();
65         }
66         return null;
67     }
68
69     private PersistenceScopes(PersistenceScopesImplementation impl) {
70         this.impl = impl;
71     }
72
73     /**
74      * Returns the persistence scopes contained in this instance.
75      *
76      * @return an array of <code>PersistenceScope</code> instances; never null.
77      */

78     public PersistenceScope[] getPersistenceScopes() {
79         return impl.getPersistenceScopes();
80     }
81
82     /**
83      * Adds a property change listener, allowing to listen on properties, e.g.
84      * {@link #PROP_PERSISTENCE_SCOPES}.
85      *
86      * @param listener the listener to add; can be null.
87      */

88     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
89         impl.addPropertyChangeListener(listener);
90     }
91
92     /**
93      * Removes a property change listener.
94      *
95      * @param listener the listener to remove; can be null.
96      */

97     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
98         impl.removePropertyChangeListener(listener);
99     }
100 }
101
Popular Tags