View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.ws.commons.schema;
21  
22  import java.util.LinkedHashMap;
23  import java.util.Map;
24  
25  public abstract class XmlSchemaObject {
26      int lineNumber;
27      int linePosition;
28      String sourceURI;
29  
30      /**
31       * a map for holding meta information
32       * Initially set to null to gain some improvement
33       * in memory. will be initialized only if a
34       * user attempts
35       */
36      private Map metaInfoMap = null;
37  
38      /**
39       * returns the metainfo map. may be null
40       * if not utilized
41       */
42      public Map getMetaInfoMap() {
43          return metaInfoMap;
44      }
45  
46      /**
47       * Directly set the meta info map into the schema element
48       * @param metaInfoMap
49       */
50      public void setMetaInfoMap(Map metaInfoMap) {
51          this.metaInfoMap = metaInfoMap;
52      }
53  
54      /**
55       * Add a value to the meta info map
56       * will be initialized if not used
57       * previously
58       * @param key
59       * @param value
60       */
61      public void addMetaInfo(Object key,Object value){
62        if (metaInfoMap==null){
63            metaInfoMap =  new LinkedHashMap();
64        }
65  
66        metaInfoMap.put(key,value);
67      }
68  
69  
70      /**
71       * Creates new XmlSchemaObject
72       */
73      protected XmlSchemaObject() {
74      }
75  
76      public int getLineNumber() {
77          return lineNumber;
78      }
79  
80      public void setLineNumber(int lineNumber) {
81          this.lineNumber = lineNumber;
82      }
83  
84      public int getLinePosition() {
85          return linePosition;
86      }
87  
88      public void setLinePosition(int linePosition) {
89          this.linePosition = linePosition;
90      }
91  
92      public String getSourceURI() {
93          return sourceURI;
94      }
95  
96      public void setSourceURI(String sourceURI) {
97          this.sourceURI = sourceURI;
98      }
99  
100     public boolean equals(Object what) {
101         if (what == this) {
102             return true;
103         }
104 
105         // note: instanceof returns false if its first operand is null 
106         if (!(what instanceof XmlSchemaObject)) {
107             return false;
108         }
109 
110         XmlSchemaObject xso = (XmlSchemaObject) what;
111 
112         if (this.lineNumber != xso.lineNumber) {
113             return false;
114         }
115 
116         if (this.linePosition != xso.linePosition) {
117             return false;
118         }
119 
120         if (this.sourceURI != null) {
121             if (!this.sourceURI.equals(xso.sourceURI)) {
122                 return false;
123             }
124         } else {
125             if (xso.sourceURI != null) {
126                 return false;
127             }
128         }
129 
130         return true;
131     }
132 
133     public String toString(String prefix, int tab) {
134         String xml = new String();
135         for (int i = 0; i < tab; i++)
136             xml += "\t";
137 
138         xml += this.getClass().toString() + "\n";
139         return xml;
140     }
141 }