KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > appclient > jws > ContentOrigin


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.appclient.jws;
25
26 import com.sun.enterprise.deployment.Application;
27 import java.io.File JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.net.URI JavaDoc;
30 import java.net.URISyntaxException JavaDoc;
31 import java.util.Collection JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.Properties JavaDoc;
35
36 /**
37  * Represents the origin of some content to be served to Java Web Start.
38  * @author tjquinn
39  */

40 public abstract class ContentOrigin {
41
42     protected static String JavaDoc lineSep = System.getProperty("line.separator");
43     
44     /**
45      *Map from URL path to the content for each file this app or
46      *app client supports.
47      */

48     protected Map JavaDoc<String JavaDoc,Content> pathToContent;
49
50     /** boolean indicating whether adhoc path is registered with container **/
51     private boolean adhocPathRegistered = false;
52
53     /**
54      *Creates a new instance of the Entry class to record an app client
55      *or J2EE application.
56      *@param the application (descriptor) for the app client or J2EE app
57      */

58     public ContentOrigin() {
59         pathToContent = new HashMap JavaDoc<String JavaDoc,Content>();
60     }
61
62     /**
63      *Returns whether the administrator has enabled this content origin (either
64      *a Java EE application or a stand-alone app client) for Java Web Start
65      *access.
66      *@return boolean indicating whether the module's app clients are enabled for JWS access
67      */

68     public abstract boolean isEnabled();
69     
70     protected Content getContent(String JavaDoc contentKey) {
71         return pathToContent.get(contentKey);
72     }
73
74     protected DynamicContent addDynamicContent(String JavaDoc path, String JavaDoc template, Properties JavaDoc tokenValues, String JavaDoc mimeType) throws IOException JavaDoc {
75         return addDynamicContent(path, template, tokenValues, mimeType, false /* requiresElevatedPrivs */);
76     }
77     
78     protected DynamicContent addDynamicContent(
79             String JavaDoc path,
80             String JavaDoc template,
81             Properties JavaDoc tokenValues,
82             String JavaDoc mimeType,
83             boolean requiresElevatedPrivs) {
84         // merge - future
85
String JavaDoc docText = Util.replaceTokens(template, tokenValues);
86         String JavaDoc contentKey = getContentKeyPrefix() + path;
87         DynamicContent result = new DynamicContent(this, contentKey, path, docText, mimeType, requiresElevatedPrivs);
88         pathToContent.put(result.getContentKey(), result);
89         return result;
90     }
91
92     protected DynamicContent addDynamicContent(DynamicContent content) {
93         pathToContent.put(content.getContentKey(), content);
94         return content;
95     }
96     
97     protected StaticContent addStaticContent(String JavaDoc path, URI JavaDoc installRootURI, File JavaDoc file) throws URISyntaxException JavaDoc {
98         String JavaDoc contentKey = getContentKeyPrefix() + path;
99         StaticContent result = new StaticContent(this, contentKey, path, file, installRootURI, false /* isMainJar */);
100         return addStaticContent(result);
101     }
102     
103     protected StaticContent addStaticContent(StaticContent content) {
104         pathToContent.put(content.getContentKey(), content);
105         return content;
106     }
107
108     /**
109      *Returns the prefix for content keys for content from this origin.
110      *@return the content key prefix for this origin
111      */

112     protected abstract String JavaDoc getContentKeyPrefix();
113     
114     /**
115      *Returns a collection of this origin's contents.
116      *@param map from content keys to contents
117      */

118     public Collection JavaDoc<Content> getContents() {
119         return pathToContent.values();
120     }
121
122     /**
123      *Mark the origin as registered with webcontainer.
124      */

125     void adhocPathRegistered() {
126         adhocPathRegistered=true;
127     }
128
129     /**
130      *Return a boolean indicating whether this
131      *is registerd with the webcontainer.
132      */

133     boolean isAdhocPathRegistered() {
134         return adhocPathRegistered;
135     }
136     
137     /**
138      *Returns a longer display of information about this origin
139      *@return detailed summary of this instance
140      */

141     public String JavaDoc toLongString() {
142         return toString() + pathToContent.toString();
143     }
144 }
145
Popular Tags