KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > autoupdate > AutoupdateType


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.autoupdate;
21
22 import java.util.*;
23
24 import org.openide.util.HelpCtx;
25 import org.openide.util.NbBundle;
26 import org.openide.ServiceType;
27 import org.openide.util.Lookup;
28
29 /** Service type representing autoupdate server
30 *
31 * @author Ales Kemr
32 */

33 public abstract class AutoupdateType extends org.openide.ServiceType
34 {
35
36     /** serialVersionUID */
37     static final long serialVersionUID = 362844512378569452L;
38
39     final static String JavaDoc PROP_ENABLED = "enabled"; // NOI18N
40
final static String JavaDoc PROP_LAST_TIME_STAMP = "lastTimeStamp"; // NOI18N
41

42     /** Holds value of property enabled. */
43     private boolean enabled = true;
44     
45     /** Holds value of property lastTimeStamp. */
46     private Date lastTimeStamp;
47     
48     static {
49         if ( java.beans.PropertyEditorManager.findEditor( ServiceType.class ) != null )
50             java.beans.PropertyEditorManager.registerEditor(
51                 AutoupdateType.class,
52                 java.beans.PropertyEditorManager.findEditor( ServiceType.class ).getClass()
53             );
54     }
55     
56     public AutoupdateType() {
57     }
58
59     /** @return human presentable name */
60     public String JavaDoc displayName() {
61         return NbBundle.getBundle( AutoupdateType.class).getString("CTL_Settings_Name");
62     }
63
64     public HelpCtx getHelpCtx () {
65         return null;
66     }
67
68     public abstract Updates connectForUpdates();
69     
70     /** Get all registered autoupdate types.
71     * @return enumeration of <code>autoupdateType</code>s
72     */

73     public static Enumeration autoupdateTypes () {
74         Collection col = Lookup.getDefault ().lookup ( new Lookup.Template( AutoupdateType.class ) ).allInstances();
75         Iterator it = col.iterator();
76         java.util.List JavaDoc lst = new ArrayList();
77         while ( it.hasNext() ) {
78             AutoupdateType at = (AutoupdateType)it.next();
79             if (at instanceof XMLAutoupdateType) {
80                 // don't add a unvalid XMLAutoupdateType
81
if (((XMLAutoupdateType) at).isValid ()) {
82                     lst.add (at);
83                 }
84             } else {
85                 // other types are added as default
86
lst.add (at);
87             }
88         }
89         return Collections.enumeration( lst );
90     }
91
92     /** Find the
93     * autoupdate type implemented as a given class, among the services registered to the
94     * system.
95     * <P>
96     * This should be used during (de-)serialization
97     * of the specific autoupdate type for a data object: only store its class name
98     * and then try to find the autoupdate implemented by that class later.
99     *
100     * @param clazz the class of the autoupdate type looked for
101     * @return the desired autoupdate type or <code>null</code> if it does not exist
102     */

103     public static AutoupdateType find (Class JavaDoc clazz) {
104         return (AutoupdateType) Lookup.getDefault ().lookup ( AutoupdateType.class );
105     }
106
107     /** Find the
108     * autoupdate with requested name, among the services registered to the
109     * system.
110     * <P>
111     * This should be used during (de-)serialization
112     * of the specific autoupdate type for a data object: only store its name
113     * and then try to find the debugger later.
114     *
115     * @param name (display) name of autoupdate to find
116     * @return the desired autoupdate or <code>null</code> if it does not exist
117     */

118     public static AutoupdateType find (String JavaDoc name) {
119         Iterator it = Lookup.getDefault ().lookup ( new Lookup.Template( AutoupdateType.class ) ).allInstances().iterator();
120         while ( it.hasNext() ) {
121             AutoupdateType at = (AutoupdateType)it.next();
122             if ( name.equals( at.getName() ) )
123                 return at;
124         }
125         return null;
126     }
127
128     /** Gets the default autoupdate type in the system.
129      * Can return null if no autoupdate types are defined.
130     */

131     public static AutoupdateType getDefault () {
132         if (autoupdateTypes ().hasMoreElements ()) {
133             return (AutoupdateType)autoupdateTypes ().nextElement ();
134         } else {
135             return null;
136         }
137     }
138
139     /** Getter for property enabled.
140      * @return Value of property enabled.
141      */

142     public boolean isEnabled() {
143         return enabled;
144     }
145     
146     /** Setter for property enabled.
147      * @param enabled New value of property enabled.
148      */

149     public void setEnabled(boolean enabled) {
150         boolean old = this.enabled;
151         this.enabled = enabled;
152         firePropertyChange( PROP_ENABLED, old ? Boolean.TRUE : Boolean.FALSE, enabled ? Boolean.TRUE : Boolean.FALSE );
153     }
154     
155     /** Getter for property lastTimeStamp.
156      * @return Value of property lastTimeStamp.
157      */

158     public Date getLastTimeStamp() {
159         return lastTimeStamp;
160     }
161     
162     /** Setter for property lastTimeStamp.
163      * @param lastTimeStamp New value of property lastTimeStamp.
164      */

165     public void setLastTimeStamp(Date lastTimeStamp) {
166         Date oldTime = this.lastTimeStamp;
167         this.lastTimeStamp = lastTimeStamp;
168         firePropertyChange (PROP_LAST_TIME_STAMP, oldTime, lastTimeStamp);
169     }
170     
171 }
172
173
Popular Tags