KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > convert > xml > SecurityConstraintImpl


1 /**
2  * This class was generated from a set of XML constraints
3  * by the Enhydra Zeus XML Data Binding Framework. All
4  * source code in this file is constructed specifically
5  * to work with other Zeus-generated classes. If you
6  * modify this file by hand, you run the risk of breaking
7  * this interoperation, as well as introducing errors in
8  * source code compilation.
9  *
10  * * * * * MODIFY THIS FILE AT YOUR OWN RISK * * * * *
11  *
12  * To find out more about the Enhydra Zeus framework, you
13  * can point your browser at <http://zeus.enhydra.org>
14  * where you can download releases, join and discuss Zeus
15  * on user and developer mailing lists, and access source
16  * code. Please report any bugs through that website.
17  */

18 package org.enhydra.convert.xml;
19
20 // Global Implementation Import Statements
21
import java.io.File JavaDoc;
22 import java.io.FileReader JavaDoc;
23 import java.io.FileWriter JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.InputStreamReader JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.OutputStream JavaDoc;
28 import java.io.OutputStreamWriter JavaDoc;
29 import java.io.Reader JavaDoc;
30 import java.io.Writer JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.Map JavaDoc;
34 import org.xml.sax.EntityResolver JavaDoc;
35 import org.xml.sax.ErrorHandler JavaDoc;
36 import org.xml.sax.InputSource JavaDoc;
37 import org.xml.sax.Locator JavaDoc;
38 import org.xml.sax.SAXException JavaDoc;
39 import org.xml.sax.SAXParseException JavaDoc;
40 import org.xml.sax.XMLReader JavaDoc;
41 import org.xml.sax.ext.LexicalHandler JavaDoc;
42 import org.xml.sax.helpers.DefaultHandler JavaDoc;
43 import org.xml.sax.helpers.XMLReaderFactory JavaDoc;
44
45 // Local Implementation Import Statements
46
import java.util.Iterator JavaDoc;
47 import java.util.List JavaDoc;
48 import java.util.LinkedList JavaDoc;
49
50 public class SecurityConstraintImpl extends DefaultHandler JavaDoc implements Cloneable JavaDoc, Unmarshallable, LexicalHandler JavaDoc, SecurityConstraint {
51
52     private DisplayName displayName;
53     private List JavaDoc webResourceCollectionList;
54     private AuthConstraint authConstraint;
55     private UserDataConstraint userDataConstraint;
56     private String JavaDoc id;
57     private boolean zeus_IdSet;
58
59     /** Any DOCTYPE reference/statements. */
60     private String JavaDoc docTypeString;
61
62     /** The encoding for the output document */
63     private String JavaDoc outputEncoding;
64
65     /** The current node in unmarshalling */
66     private Unmarshallable zeus_currentUNode;
67
68     /** The parent node in unmarshalling */
69     private Unmarshallable zeus_parentUNode;
70
71     /** Whether this node has been handled */
72     private boolean zeus_thisNodeHandled = false;
73
74     /** Whether a DTD exists for an unmarshal call */
75     private boolean hasDTD;
76
77     /** Whether validation is occurring */
78     private boolean validate;
79
80     /** The namespace mappings on this element */
81     private Map JavaDoc namespaceMappings;
82
83     /** The EntityResolver for SAX parsing to use */
84     private static EntityResolver JavaDoc entityResolver;
85
86     /** The ErrorHandler for SAX parsing to use */
87     private static ErrorHandler JavaDoc errorHandler;
88
89     private static SecurityConstraintImpl prototype = null;
90
91     public static void setPrototype(SecurityConstraintImpl prototype) {
92         SecurityConstraintImpl.prototype = prototype;
93     }
94     public static SecurityConstraintImpl newInstance() {
95         try {
96             return (prototype!=null)?(SecurityConstraintImpl)prototype.clone(): new SecurityConstraintImpl();
97         } catch (CloneNotSupportedException JavaDoc e) {
98             return null; // never
99
}
100     }
101     public SecurityConstraintImpl() {
102         webResourceCollectionList = new LinkedList JavaDoc();
103         zeus_IdSet = false;
104         docTypeString = "";
105         hasDTD = false;
106         validate = false;
107         namespaceMappings = new HashMap JavaDoc();
108     }
109
110     public DisplayName getDisplayName() {
111         return displayName;
112     }
113
114     public void setDisplayName(DisplayName displayName) {
115         this.displayName = displayName;
116     }
117
118     public List JavaDoc getWebResourceCollectionList() {
119         return webResourceCollectionList;
120     }
121
122     public void setWebResourceCollectionList(List JavaDoc webResourceCollectionList) {
123         this.webResourceCollectionList = webResourceCollectionList;
124     }
125
126     public void addWebResourceCollection(WebResourceCollection webResourceCollection) {
127         webResourceCollectionList.add(webResourceCollection);
128     }
129
130     public void removeWebResourceCollection(WebResourceCollection webResourceCollection) {
131         webResourceCollectionList.remove(webResourceCollection);
132     }
133
134     public AuthConstraint getAuthConstraint() {
135         return authConstraint;
136     }
137
138     public void setAuthConstraint(AuthConstraint authConstraint) {
139         this.authConstraint = authConstraint;
140     }
141
142     public UserDataConstraint getUserDataConstraint() {
143         return userDataConstraint;
144     }
145
146     public void setUserDataConstraint(UserDataConstraint userDataConstraint) {
147         this.userDataConstraint = userDataConstraint;
148     }
149
150     public String JavaDoc getId() {
151         return id;
152     }
153
154     public void setId(String JavaDoc id) {
155         this.id = id;
156         zeus_IdSet = true;
157     }
158
159     public void setDocType(String JavaDoc name, String JavaDoc publicID, String JavaDoc systemID) {
160         try {
161             startDTD(name, publicID, systemID);
162         } catch (SAXException JavaDoc neverHappens) { }
163     }
164
165     public void setOutputEncoding(String JavaDoc outputEncoding) {
166         this.outputEncoding = outputEncoding;
167     }
168
169     public void marshal(File JavaDoc file) throws IOException JavaDoc {
170         // Delegate to the marshal(Writer) method
171
marshal(new FileWriter JavaDoc(file));
172     }
173
174     public void marshal(OutputStream JavaDoc outputStream) throws IOException JavaDoc {
175         // Delegate to the marshal(Writer) method
176
marshal(new OutputStreamWriter JavaDoc(outputStream));
177     }
178
179     public void marshal(Writer JavaDoc writer) throws IOException JavaDoc {
180         // Write out the XML declaration
181
writer.write("<?xml version=\"1.0\" ");
182         if (outputEncoding != null) {
183             writer.write("encoding=\"");
184             writer.write(outputEncoding);
185             writer.write("\"?>\n\n");
186
187         } else {
188             writer.write("encoding=\"UTF-8\"?>\n\n");
189
190         }
191         // Handle DOCTYPE declaration
192
writer.write(docTypeString);
193         writer.write("\n");
194         // Now start the recursive writing
195
writeXMLRepresentation(writer, "");
196
197         // Close up
198
writer.flush();
199         writer.close();
200     }
201
202     protected void writeXMLRepresentation(Writer JavaDoc writer,
203                                           String JavaDoc indent)
204         throws IOException JavaDoc {
205
206         writer.write(indent);
207         writer.write("<security-constraint");
208
209         // Handle namespace mappings (if needed)
210
for (Iterator JavaDoc i = namespaceMappings.keySet().iterator(); i.hasNext(); ) {
211             String JavaDoc prefix = (String JavaDoc)i.next();
212             String JavaDoc uri = (String JavaDoc)namespaceMappings.get(prefix);
213             writer.write(" xmlns");
214             if (!prefix.trim().equals("")) {
215                 writer.write(":");
216                 writer.write(prefix);
217             }
218             writer.write("=\"");
219             writer.write(uri);
220             writer.write("\"\n ");
221         }
222
223         // Handle attributes (if needed)
224
if (zeus_IdSet) {
225             writer.write(" id=\"");
226             writer.write(escapeAttributeValue(id));
227             writer.write("\"");
228         }
229         writer.write(">");
230         writer.write("\n");
231
232         // Handle child elements
233
if (displayName != null) {
234             ((DisplayNameImpl)displayName).writeXMLRepresentation(writer,
235                 new StringBuffer JavaDoc(indent).append(" ").toString());
236         }
237
238         for (Iterator JavaDoc i=webResourceCollectionList.iterator(); i.hasNext(); ) {
239             WebResourceCollectionImpl webResourceCollection = (WebResourceCollectionImpl)i.next();
240             webResourceCollection.writeXMLRepresentation(writer,
241                 new StringBuffer JavaDoc(indent).append(" ").toString());
242         }
243         if (authConstraint != null) {
244             ((AuthConstraintImpl)authConstraint).writeXMLRepresentation(writer,
245                 new StringBuffer JavaDoc(indent).append(" ").toString());
246         }
247
248         if (userDataConstraint != null) {
249             ((UserDataConstraintImpl)userDataConstraint).writeXMLRepresentation(writer,
250                 new StringBuffer JavaDoc(indent).append(" ").toString());
251         }
252
253         writer.write(indent);
254         writer.write("</security-constraint>\n");
255     }
256
257     private String JavaDoc escapeAttributeValue(String JavaDoc attributeValue) {
258         String JavaDoc returnValue = attributeValue;
259         for (int i = 0; i < returnValue.length(); i++) {
260             char ch = returnValue.charAt(i);
261             if (ch == '"') {
262                 returnValue = new StringBuffer JavaDoc()
263                     .append(returnValue.substring(0, i))
264                     .append("&quot;")
265                     .append(returnValue.substring(i+1))
266                     .toString();
267             }
268         }
269         return returnValue;
270     }
271
272     private String JavaDoc escapeTextValue(String JavaDoc textValue) {
273         String JavaDoc returnValue = textValue;
274         for (int i = 0; i < returnValue.length(); i++) {
275             char ch = returnValue.charAt(i);
276             if (ch == '<') {
277                 returnValue = new StringBuffer JavaDoc()
278                     .append(returnValue.substring(0, i))
279                     .append("&lt;")
280                     .append(returnValue.substring(i+1))
281                     .toString();
282             } else if (ch == '>') {
283                 returnValue = new StringBuffer JavaDoc()
284                     .append(returnValue.substring(0, i))
285                     .append("&gt;")
286                     .append(returnValue.substring(i+1))
287                     .toString();
288             }
289         }
290         return returnValue;
291     }
292
293     /**
294      * <p>
295      * This sets a SAX <code>EntityResolver</code> for this unmarshalling process.
296      * </p>
297      *
298      * @param resolver the entity resolver to use.
299      */

300     public static void setEntityResolver(EntityResolver JavaDoc resolver) {
301         entityResolver = resolver;
302     }
303
304     /**
305      * <p>
306      * This sets a SAX <code>ErrorHandler</code> for this unmarshalling process.
307      * </p>
308      *
309      * @param handler the entity resolver to use.
310      */

311     public static void setErrorHandler(ErrorHandler JavaDoc handler) {
312         errorHandler = handler;
313     }
314
315     public static SecurityConstraint unmarshal(File JavaDoc file) throws IOException JavaDoc {
316         // Delegate to the unmarshal(Reader) method
317
return unmarshal(new FileReader JavaDoc(file));
318     }
319
320     public static SecurityConstraint unmarshal(File JavaDoc file, boolean validate) throws IOException JavaDoc {
321         // Delegate to the unmarshal(Reader) method
322
return unmarshal(new FileReader JavaDoc(file), validate);
323     }
324
325     public static SecurityConstraint unmarshal(InputStream JavaDoc inputStream) throws IOException JavaDoc {
326         // Delegate to the unmarshal(Reader) method
327
return unmarshal(new InputStreamReader JavaDoc(inputStream));
328     }
329
330     public static SecurityConstraint unmarshal(InputStream JavaDoc inputStream, boolean validate) throws IOException JavaDoc {
331         // Delegate to the unmarshal(Reader) method
332
return unmarshal(new InputStreamReader JavaDoc(inputStream), validate);
333     }
334
335     public static SecurityConstraint unmarshal(Reader JavaDoc reader) throws IOException JavaDoc {
336         // Delegate with default validation value
337
return unmarshal(reader, false);
338     }
339
340     public static SecurityConstraint unmarshal(Reader JavaDoc reader, boolean validate) throws IOException JavaDoc {
341         SecurityConstraintImpl securityConstraint = SecurityConstraintImpl.newInstance();
342         securityConstraint.setValidating(validate);
343         securityConstraint.setCurrentUNode(securityConstraint);
344         securityConstraint.setParentUNode(null);
345         // Load the XML parser
346
XMLReader JavaDoc parser = null;
347         String JavaDoc parserClass = System.getProperty("org.xml.sax.driver",
348             "org.apache.xerces.parsers.SAXParser");
349         try {
350             parser = XMLReaderFactory.createXMLReader(parserClass);
351
352             // Set entity resolver, if needed
353
if (entityResolver != null) {
354                 parser.setEntityResolver(entityResolver);
355             }
356
357             // Set error handler
358
parser.setErrorHandler(securityConstraint);
359
360             // Register lexical handler
361
parser.setProperty("http://xml.org/sax/properties/lexical-handler", securityConstraint);
362
363             // Register content handler
364
parser.setContentHandler(securityConstraint);
365         } catch (SAXException JavaDoc e) {
366             throw new IOException JavaDoc("Could not load XML parser: " +
367                 e.getMessage());
368         }
369
370         InputSource JavaDoc inputSource = new InputSource JavaDoc(reader);
371         try {
372             parser.setFeature("http://xml.org/sax/features/validation", new Boolean JavaDoc(validate).booleanValue());
373             parser.setFeature("http://xml.org/sax/features/namespaces", true);
374             parser.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
375             parser.parse(inputSource);
376         } catch (SAXException JavaDoc e) {
377             throw new IOException JavaDoc("Error parsing XML document: " +
378                 e.getMessage());
379         }
380
381         // Return the resultant object
382
return securityConstraint;
383     }
384
385     public Unmarshallable getParentUNode() {
386         return zeus_parentUNode;
387     }
388
389     public void setParentUNode(Unmarshallable parentUNode) {
390         this.zeus_parentUNode = parentUNode;
391     }
392
393     public Unmarshallable getCurrentUNode() {
394         return zeus_currentUNode;
395     }
396
397     public void setCurrentUNode(Unmarshallable currentUNode) {
398         this.zeus_currentUNode = currentUNode;
399     }
400
401     public void setValidating(boolean validate) {
402         this.validate = validate;
403     }
404
405     public void startDocument() throws SAXException JavaDoc {
406         // no-op
407
}
408
409     public void setDocumentLocator(Locator JavaDoc locator) {
410         // no-op
411
}
412
413     public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri)
414         throws SAXException JavaDoc {
415         namespaceMappings.put(prefix, uri);
416     }
417
418     public void startElement(String JavaDoc namespaceURI, String JavaDoc localName,
419                              String JavaDoc qName, org.xml.sax.Attributes JavaDoc atts)
420         throws SAXException JavaDoc {
421
422         // Feed this to the correct ContentHandler
423
Unmarshallable current = getCurrentUNode();
424         if (current != this) {
425             current.startElement(namespaceURI, localName, qName, atts);
426             return;
427         }
428
429         // See if we handle, or we delegate
430
if ((localName.equals("security-constraint")) && (!zeus_thisNodeHandled)) {
431             // Handle ourselves
432
for (int i=0, len=atts.getLength(); i<len; i++) {
433                 String JavaDoc attName= atts.getLocalName(i);
434                 String JavaDoc attValue = atts.getValue(i);
435                 if (attName.equals("id")) {
436                     setId(attValue);
437                 }
438             }
439             zeus_thisNodeHandled = true;
440             return;
441         } else {
442             // Delegate handling
443
if (localName.equals("display-name") && (displayName==null)) {
444                 DisplayNameImpl displayName = DisplayNameImpl.newInstance();
445                 current = getCurrentUNode();
446                 displayName.setParentUNode(current);
447                 displayName.setCurrentUNode(displayName);
448                 this.setCurrentUNode(displayName);
449                 displayName.startElement(namespaceURI, localName, qName, atts);
450                 // Add this value in
451
this.displayName = displayName;
452                 return;
453             }
454             if (localName.equals("web-resource-collection")) {
455                 WebResourceCollectionImpl webResourceCollection = WebResourceCollectionImpl.newInstance();
456                 current = getCurrentUNode();
457                 webResourceCollection.setParentUNode(current);
458                 webResourceCollection.setCurrentUNode(webResourceCollection);
459                 this.setCurrentUNode(webResourceCollection);
460                 webResourceCollection.startElement(namespaceURI, localName, qName, atts);
461                 // Add this value in
462
webResourceCollectionList.add(webResourceCollection);
463                 return;
464             }
465             if (localName.equals("auth-constraint") && (authConstraint==null)) {
466                 AuthConstraintImpl authConstraint = AuthConstraintImpl.newInstance();
467                 current = getCurrentUNode();
468                 authConstraint.setParentUNode(current);
469                 authConstraint.setCurrentUNode(authConstraint);
470                 this.setCurrentUNode(authConstraint);
471                 authConstraint.startElement(namespaceURI, localName, qName, atts);
472                 // Add this value in
473
this.authConstraint = authConstraint;
474                 return;
475             }
476             if (localName.equals("user-data-constraint") && (userDataConstraint==null)) {
477                 UserDataConstraintImpl userDataConstraint = UserDataConstraintImpl.newInstance();
478                 current = getCurrentUNode();
479                 userDataConstraint.setParentUNode(current);
480                 userDataConstraint.setCurrentUNode(userDataConstraint);
481                 this.setCurrentUNode(userDataConstraint);
482                 userDataConstraint.startElement(namespaceURI, localName, qName, atts);
483                 // Add this value in
484
this.userDataConstraint = userDataConstraint;
485                 return;
486             }
487         }
488     }
489
490     public void endElement(String JavaDoc namespaceURI, String JavaDoc localName,
491                            String JavaDoc qName)
492         throws SAXException JavaDoc {
493
494         Unmarshallable current = getCurrentUNode();
495         if (current != this) {
496             current.endElement(namespaceURI, localName, qName);
497             return;
498         }
499
500         Unmarshallable parent = getCurrentUNode().getParentUNode();
501         if (parent != null) {
502             parent.setCurrentUNode(parent);
503         }
504     }
505
506     public void characters(char[] ch, int start, int len)
507         throws SAXException JavaDoc {
508
509         // Feed this to the correct ContentHandler
510
Unmarshallable current = getCurrentUNode();
511         if (current != this) {
512             current.characters(ch, start, len);
513             return;
514         }
515
516         String JavaDoc text = new String JavaDoc(ch, start, len);
517     }
518
519     public void comment(char ch[], int start, int len) throws SAXException JavaDoc {
520         // Currently no-op
521
}
522
523     public void warning(SAXParseException JavaDoc e) throws SAXException JavaDoc {
524         if (errorHandler != null) {
525             errorHandler.warning(e);
526         }
527     }
528
529     public void error(SAXParseException JavaDoc e) throws SAXException JavaDoc {
530         if ((validate) && (!hasDTD)) {
531             throw new SAXException JavaDoc("Validation is turned on, but no DTD has been specified in the input XML document. Please supply a DTD through a DOCTYPE reference.");
532         }
533         if (errorHandler != null) {
534             errorHandler.error(e);
535         }
536     }
537
538     public void fatalError(SAXParseException JavaDoc e) throws SAXException JavaDoc {
539         if ((validate) && (!hasDTD)) {
540             throw new SAXException JavaDoc("Validation is turned on, but no DTD has been specified in the input XML document. Please supply a DTD through a DOCTYPE reference.");
541         }
542         if (errorHandler != null) {
543             errorHandler.fatalError(e);
544         }
545     }
546
547     public void startDTD(String JavaDoc name, String JavaDoc publicID, String JavaDoc systemID)
548         throws SAXException JavaDoc {
549
550         if ((name == null) || (name.equals(""))) {
551             docTypeString = "";
552             return;
553         }
554
555         hasDTD = true;
556         StringBuffer JavaDoc docTypeSB = new StringBuffer JavaDoc();
557         boolean hasPublic = false;
558
559         docTypeSB.append("<!DOCTYPE ")
560                  .append(name);
561
562         if ((publicID != null) && (!publicID.equals(""))) {
563             docTypeSB.append(" PUBLIC \"")
564                      .append(publicID)
565                      .append("\"");
566             hasPublic = true;
567         }
568
569         if ((systemID != null) && (!systemID.equals(""))) {
570             if (!hasPublic) {
571                 docTypeSB.append(" SYSTEM");
572             }
573             docTypeSB.append(" \"")
574                      .append(systemID)
575                      .append("\"");
576
577         }
578
579         docTypeSB.append(">");
580
581         docTypeString = docTypeSB.toString();
582     }
583
584     public void endDTD() throws SAXException JavaDoc {
585         // Currently no-op
586
}
587
588     public void startEntity(String JavaDoc name) throws SAXException JavaDoc {
589         // Currently no-op
590
}
591
592     public void endEntity(String JavaDoc name) throws SAXException JavaDoc {
593         // Currently no-op
594
}
595
596     public void startCDATA() throws SAXException JavaDoc {
597         // Currently no-op
598
}
599
600     public void endCDATA() throws SAXException JavaDoc {
601         // Currently no-op
602
}
603
604 }
605
Popular Tags