KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > impl > JMControllerImpl


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.impl;
18
19 import java.text.Format JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import javax.xml.bind.DatatypeConverterInterface;
24 import javax.xml.bind.PropertyException;
25 import javax.xml.bind.ValidationEventHandler;
26
27 import org.apache.ws.jaxme.xs.util.XsDateFormat;
28 import org.apache.ws.jaxme.xs.util.XsDateTimeFormat;
29 import org.apache.ws.jaxme.xs.util.XsTimeFormat;
30
31
32
33 /** <p>Common subclass for JMMarshallerImpl, JMUnmarshallerImpl and
34  * JMValidatorImpl.</p>
35  *
36  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
37  * @version $Id: JMControllerImpl.java,v 1.5 2005/03/04 10:41:53 jochen Exp $
38  */

39 public abstract class JMControllerImpl {
40     /** Property prefix for users private settings:
41      * "jaxme.private.". If a property
42      * name starts with this prefix, then the property value is
43      * stored in an internal Map.
44      */

45     public static final String JavaDoc JAXME_PRIVATE = "jaxme.private.";
46     
47     /** Name of the property for setting the
48      * {@link javax.xml.bind.DatatypeConverterInterface}: "jaxme.datatypeConverter".
49      */

50     public static final String JavaDoc JAXME_DATATYPE_CONVERTER = "jaxme.datatypeConverter";
51     
52     /** Property for setting an instance of {@link java.text.Format},
53      * which is being used for parsing and printing <code>xs:dateTime</code>
54      * values. Defaults to an instance of
55      * {@link org.apache.ws.jaxme.xs.util.XsDateTimeFormat}.
56      */

57     public static final String JavaDoc JAXME_FORMAT_DATETIME = "jaxme.format.dateTime";
58     
59     /** Property for setting an instance of {@link java.text.Format},
60      * which is being used for parsing and printing <code>xs:date</code>
61      * values. Defaults to an instance of
62      * {@link org.apache.ws.jaxme.xs.util.XsDateFormat}.
63      */

64     public static final String JavaDoc JAXME_FORMAT_DATE = "jaxme.format.date";
65     
66     /** Property for setting an instance of {@link java.text.Format},
67      * which is being used for parsing and printing <code>xs:time</code>
68      * values. Defaults to an instance of
69      * {@link org.apache.ws.jaxme.xs.util.XsTimeFormat}.
70      */

71     public static final String JavaDoc JAXME_FORMAT_TIME = "jaxme.format.time";
72     
73     private Map JavaDoc privateMap;
74     private JAXBContextImpl context;
75     private DatatypeConverterInterface datatypeConverter = new DatatypeConverterImpl();
76     private Format JavaDoc dateTimeFormat, dateFormat, timeFormat;
77     
78     /** Sets the property <code>pProperty</code> to the value
79      * <code>pValue</code>.
80      */

81     public void setProperty(String JavaDoc pProperty, Object JavaDoc pValue)
82     throws PropertyException {
83         if (pProperty.startsWith(JAXME_PRIVATE)) {
84             if (privateMap == null) {
85                 privateMap = new HashMap JavaDoc();
86             }
87             privateMap.put(pProperty, pValue);
88             return;
89         } else if (pProperty.equals(JAXME_DATATYPE_CONVERTER)) {
90             datatypeConverter = (DatatypeConverterInterface) pValue;
91             return;
92         } else if (JAXME_FORMAT_DATETIME.equals(pProperty)) {
93             setDateTimeFormat((Format JavaDoc) pValue);
94         } else if (JAXME_FORMAT_DATE.equals(pProperty)) {
95             setDateFormat((Format JavaDoc) pValue);
96         } else if (JAXME_FORMAT_TIME.equals(pProperty)) {
97             setTimeFormat((Format JavaDoc) pValue);
98         }
99         
100         throw new PropertyException("Unknown property: " + pProperty);
101     }
102     
103     /** Returns the value for property <code>pProperty</code>.
104      */

105     public Object JavaDoc getProperty(String JavaDoc pProperty) throws PropertyException {
106         if (pProperty.startsWith(JAXME_PRIVATE)) {
107             if (privateMap == null) { return null; }
108             return privateMap.get(pProperty);
109         } else if (pProperty.equals(JAXME_DATATYPE_CONVERTER)) {
110             return datatypeConverter;
111         } else if (JAXME_FORMAT_DATETIME.equals(pProperty)) {
112             return getDateTimeFormat();
113         } else if (JAXME_FORMAT_DATE.equals(pProperty)) {
114             return getDateFormat();
115         } else if (JAXME_FORMAT_TIME.equals(pProperty)) {
116             return getTimeFormat();
117         }
118         
119         throw new PropertyException("Unknown property: " + pProperty);
120     }
121     
122     protected ValidationEventHandler eventHandler;
123     
124     /** Returns a users event handler for validation events, if any.
125      * Defaults to null.
126      * @see #setEventHandler(ValidationEventHandler)
127      */

128     public ValidationEventHandler getEventHandler() { return eventHandler; }
129     
130     /** Sets a users event handler for validation events.
131      * Defaults to null.
132      * @see #getEventHandler()
133      */

134     public void setEventHandler(ValidationEventHandler pEventHandler) { eventHandler = pEventHandler; }
135     
136     /** Sets the marshallers or unmarshallers
137      * {@link javax.xml.bind.JAXBContext}. This is used mainly as an
138      * object factory.
139      */

140     public void setJAXBContextImpl(JAXBContextImpl pContext) { context = pContext; }
141     /** Returns the marshallers or unmarshallers
142      * {@link javax.xml.bind.JAXBContext}. This is used mainly as an
143      * object factory.
144      */

145     public JAXBContextImpl getJAXBContextImpl() { return context; }
146     
147     /** Sets the marshallers or unmarshallers datatype converter.
148      * Defaults to an instance of {@link DatatypeConverterImpl}.
149      */

150     public void setDatatypeConverter(DatatypeConverterInterface pConverter) { datatypeConverter = pConverter; }
151     /** Returns the marshallers or unmarshallers datatype converter.
152      * Defaults to an instance of {@link DatatypeConverterImpl}.
153      */

154     public DatatypeConverterInterface getDatatypeConverter() { return datatypeConverter; }
155     
156     /** <p>Sets the {@link java.text.Format} for parsing and printing
157      * <code>xs:dateTime</code> values.</p>
158      * @param pFormat An instance of {@link java.text.DateFormat} or an
159      * instance of {@link org.apache.ws.jaxme.xs.util.XsDateTimeFormat}
160      * (default).
161      */

162     public void setDateTimeFormat(Format JavaDoc pFormat) {
163         dateTimeFormat = pFormat;
164     }
165     
166     /** <p>Returns the {@link java.text.Format} for parsing and printing
167      * <code>xs:dateTime</code> values.</p>
168      * @return An instance of {@link java.text.DateFormat} or an
169      * instance of {@link org.apache.ws.jaxme.xs.util.XsDateTimeFormat}
170      * (default).
171      */

172     public Format JavaDoc getDateTimeFormat() {
173         if (dateTimeFormat == null) {
174             dateTimeFormat = new XsDateTimeFormat();
175         }
176         return dateTimeFormat;
177     }
178     
179     /** <p>Sets the {@link java.text.Format} for parsing and printing
180      * <code>xs:date</code> values.</p>
181      * @param pFormat An instance of {@link java.text.DateFormat} or an
182      * instance of {@link org.apache.ws.jaxme.xs.util.XsDateFormat}
183      * (default).
184      */

185     public void setDateFormat(Format JavaDoc pFormat) {
186         dateFormat = pFormat;
187     }
188     
189     /** <p>Returns the {@link java.text.Format} for parsing and printing
190      * <code>xs:date</code> values.</p>
191      * @return An instance of {@link java.text.DateFormat} or an
192      * instance of {@link org.apache.ws.jaxme.xs.util.XsDateFormat}
193      * (default).
194      */

195     public Format JavaDoc getDateFormat() {
196         if (dateFormat == null) {
197             dateFormat = new XsDateFormat();
198         }
199         return dateFormat;
200     }
201     
202     /** <p>Sets the {@link java.text.Format} for parsing and printing
203      * <code>xs:date</code> values.</p>
204      * @param pFormat An instance of {@link java.text.DateFormat} or an
205      * instance of {@link org.apache.ws.jaxme.xs.util.XsDateFormat}
206      * (default).
207      */

208     public void setTimeFormat(Format JavaDoc pFormat) {
209         timeFormat = pFormat;
210     }
211     
212     /** <p>Returns the {@link java.text.Format} for parsing and printing
213      * <code>xs:time</code> values.</p>
214      * @return An instance of {@link java.text.DateFormat} or an
215      * instance of {@link org.apache.ws.jaxme.xs.util.XsTimeFormat}
216      * (default).
217      */

218     public Format JavaDoc getTimeFormat() {
219         if (timeFormat == null) {
220             timeFormat = new XsTimeFormat();
221         }
222         return timeFormat;
223     }
224 }
225
Popular Tags