View Javadoc

1   /*
2    * Copyright 2004,2007 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.commons.schema;
18  
19  import java.util.LinkedHashMap;
20  import java.util.Map;
21  
22  public abstract class XmlSchemaObject {
23      int lineNumber;
24      int linePosition;
25      String sourceURI;
26  
27      /**
28       * a map for holding meta information
29       * Initially set to null to gain some improvement
30       * in memory. will be initialized only if a
31       * user attempts
32       */
33      private Map metaInfoMap = null;
34  
35      /**
36       * returns the metainfo map. may be null
37       * if not utilized
38       */
39      public Map getMetaInfoMap() {
40          return metaInfoMap;
41      }
42  
43      /**
44       * Directly set the meta info map into the schema element
45       * @param metaInfoMap
46       */
47      public void setMetaInfoMap(Map metaInfoMap) {
48          this.metaInfoMap = metaInfoMap;
49      }
50  
51      /**
52       * Add a value to the meta info map
53       * will be initialized if not used
54       * previously
55       * @param key
56       * @param value
57       */
58      public void addMetaInfo(Object key,Object value){
59        if (metaInfoMap==null){
60            metaInfoMap =  new LinkedHashMap();
61        }
62  
63        metaInfoMap.put(key,value);
64      }
65  
66  
67      /**
68       * Creates new XmlSchemaObject
69       */
70      protected XmlSchemaObject() {
71      }
72  
73      public int getLineNumber() {
74          return lineNumber;
75      }
76  
77      public void setLineNumber(int lineNumber) {
78          this.lineNumber = lineNumber;
79      }
80  
81      public int getLinePosition() {
82          return linePosition;
83      }
84  
85      public void setLinePosition(int linePosition) {
86          this.linePosition = linePosition;
87      }
88  
89      public String getSourceURI() {
90          return sourceURI;
91      }
92  
93      public void setSourceURI(String sourceURI) {
94          this.sourceURI = sourceURI;
95      }
96  
97      public boolean equals(Object what) {
98          if (what == this) {
99              return true;
100         }
101 
102         // note: instanceof returns false if its first operand is null 
103         if (!(what instanceof XmlSchemaObject)) {
104             return false;
105         }
106 
107         XmlSchemaObject xso = (XmlSchemaObject) what;
108 
109         if (this.lineNumber != xso.lineNumber) {
110             return false;
111         }
112 
113         if (this.linePosition != xso.linePosition) {
114             return false;
115         }
116 
117         if (this.sourceURI != null) {
118             if (!this.sourceURI.equals(xso.sourceURI)) {
119                 return false;
120             }
121         } else {
122             if (xso.sourceURI != null) {
123                 return false;
124             }
125         }
126 
127         return true;
128     }
129 
130     public String toString(String prefix, int tab) {
131         String xml = new String();
132         for (int i = 0; i < tab; i++)
133             xml += "\t";
134 
135         xml += this.getClass().toString() + "\n";
136         return xml;
137     }
138 }