KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > convertor > ConvertorDescriptor


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.api.convertor;
21
22 import org.netbeans.spi.convertor.Convertor;
23
24 /**
25  * Convertor descriptor describes basic capability of the convertor,
26  * that is the XML namespace and element name which the convertor
27  * is capable to read, and (optional) class name which instances the convertor is
28  * capable to persist. Only the instances of the particular Java class
29  * will be persisted by the convertor. All subclasses must have their own
30  * convertors. For more details about semantics of these attributes see
31  * {@link org.netbeans.spi.convertor.Convertor} class Javadoc.
32  *
33  * @author David Konecny
34  */

35 public final class ConvertorDescriptor extends Object JavaDoc {
36     
37     private String JavaDoc namespace;
38     private String JavaDoc rootElement;
39     private String JavaDoc writes;
40     private Convertor convertor;
41     
42     ConvertorDescriptor(Convertor convertor, String JavaDoc namespace, String JavaDoc rootElement, String JavaDoc writes) {
43         assert namespace != null && rootElement != null;
44         this.namespace = namespace;
45         this.rootElement = rootElement;
46         this.writes = writes;
47         this.convertor = convertor;
48     }
49
50     /**
51      * Gets the XML namespace which the convertor can read.
52      *
53      * @return XML namespace; cannot be null
54      */

55     public String JavaDoc getNamespace() {
56         return namespace;
57     }
58     
59     /**
60      * Gets the root element name which the convertor can read.
61      *
62      * @return root element name; cannot be null
63      */

64     public String JavaDoc getElementName() {
65         return rootElement;
66     }
67     
68     /**
69      * Gets the fully qualified name of the class which instances
70      * the convertor can persist. It can be null what means
71      * that convertor cannot persist any class.
72      *
73      * @return fully qualified name of the class or null if
74      * this convertor does not persist any class
75      */

76     public String JavaDoc getClassName() {
77         return writes;
78     }
79
80     public boolean equals(Object JavaDoc o) {
81         if (!(o instanceof ConvertorDescriptor)) {
82             return false;
83         }
84         ConvertorDescriptor cd = (ConvertorDescriptor)o;
85         return namespace.equals(cd.namespace) &&
86                 rootElement.equals(cd.rootElement) &&
87                 (writes != null ? writes.equals(cd.writes) : cd.writes == null);
88     }
89    
90     public int hashCode() {
91         int result = namespace.hashCode();
92         result += 13 * rootElement.hashCode();
93         if (writes != null) {
94             result += 17 * writes.hashCode();
95         }
96         return result;
97     }
98     
99     public String JavaDoc toString() {
100         return "ConvertorDescriptor[namespace='"+namespace+"', element='"+rootElement+"', writes='"+writes+"', convertor='"+convertor+"']"+super.toString(); // NOI18N
101
}
102
103     Convertor getConvertor() {
104         return convertor;
105     }
106     
107 }
108
Popular Tags