KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > core > model > URLEntryModel


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.core.model;
12
13 import java.net.MalformedURLException JavaDoc;
14 import java.net.URL JavaDoc;
15
16 import org.eclipse.update.core.IURLEntry;
17 import org.eclipse.update.internal.core.UpdateCore;
18
19 /**
20  * Annotated URL model object.
21  * <p>
22  * This class may be instantiated or subclassed by clients. However, in most
23  * cases clients should instead instantiate or subclass the provided
24  * concrete implementation of this model.
25  * </p>
26  * <p>
27  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
28  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
29  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
30  * (repeatedly) as the API evolves.
31  * </p>
32  * @see org.eclipse.update.core.URLEntry
33  * @since 2.0
34  */

35
36 public class URLEntryModel extends ModelObject {
37     
38     private String JavaDoc annotation;
39     private String JavaDoc localizedAnnotation;
40     private String JavaDoc urlString;
41     private URL JavaDoc url;
42     
43     private int type = IURLEntry.UPDATE_SITE;
44     
45     //performance
46
private URL JavaDoc bundleURL;
47     private URL JavaDoc base;
48     private boolean resolved=false;
49     
50     /**
51      * Creates a uninitialized annotated URL model object.
52      *
53      * @since 2.0
54      */

55     public URLEntryModel() {
56         super();
57     }
58         
59     /**
60      * Returns the url annotation. If the model object has been resolved,
61      * the annotation is localized.
62      *
63      * @return url annotation, or <code>null</code>.
64      * @since 2.0
65      */

66     public String JavaDoc getAnnotation() {
67         delayedResolve();
68         if (localizedAnnotation != null)
69             return localizedAnnotation;
70         else
71             return annotation;
72     }
73         
74     /**
75      * returns the non-localized url annotation.
76      *
77      * @return non-localized url annotation, or <code>null</code>.
78      * @since 2.0
79      */

80     public String JavaDoc getAnnotationNonLocalized() {
81         return annotation;
82     }
83
84     /**
85      * Returns the unresolved url string.
86      *
87      * @return url string, or <code>null</code>
88      * @since 2.0
89      */

90     public String JavaDoc getURLString() {
91         delayedResolve();
92         return urlString;
93     }
94     
95     /**
96      * Returns the resolved URL.
97      *
98      * @return url, or <code>null</code>
99      * @since 2.0
100      */

101     public URL JavaDoc getURL() {
102         delayedResolve();
103         return url;
104     }
105     
106     /**
107      * Sets the annotation.
108      * Throws a runtime exception if this object is marked read-only.
109      *
110      * @param annotation annotation
111      * @since 2.0
112      */

113     public void setAnnotation(String JavaDoc annotation) {
114         assertIsWriteable();
115         this.annotation = annotation;
116         this.localizedAnnotation = null;
117     }
118     
119     /**
120      * Sets the url string
121      * Throws a runtime exception if this object is marked read-only.
122      *
123      * @param urlString url string
124      * @since 2.0
125      */

126     public void setURLString(String JavaDoc urlString) {
127         assertIsWriteable();
128         this.urlString = urlString;
129         this.url = null;
130     }
131     
132     /**
133      * Resolve the model object.
134      * Any URL strings in the model are resolved relative to the
135      * base URL argument. Any translatable strings in the model that are
136      * specified as translation keys are localized using the supplied
137      * resource bundle.
138      *
139      * @param base URL
140      * @param bundleURL resource bundle url
141      * @exception MalformedURLException
142      * @since 2.0
143      */

144     public void resolve(URL JavaDoc base, URL JavaDoc bundleURL) throws MalformedURLException JavaDoc {
145         this.base = base;
146         this.bundleURL = bundleURL;
147     }
148
149
150     private void delayedResolve() {
151         
152         //PERF: delay resolution
153
if (resolved)return;
154         
155         resolved= true;
156         // resolve local elements
157
localizedAnnotation = resolveNLString(bundleURL, annotation);
158         try {
159             url = resolveURL(base,bundleURL, urlString);
160         } catch (MalformedURLException JavaDoc e){
161             UpdateCore.warn("",e); //$NON-NLS-1$
162
}
163     }
164
165     /**
166      * Returns the specified type.
167      *
168      * @since 2.1
169      */

170     public int getType() {
171         return type;
172     }
173
174     /**
175      * Method setType.
176      * @param i
177      */

178     public void setType(int i) {
179         type = i;
180     }
181 }
182
Popular Tags