Source Code Cross Referenced for CatalogEntry.java in  » 6.0-JDK-Modules » jaxb-xjc » com » sun » org » apache » xml » internal » resolver » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » jaxb xjc » com.sun.org.apache.xml.internal.resolver 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // CatalogEntry.java - Represents Catalog entries
002:
003:        /*
004:         * Copyright 2001-2004 The Apache Software Foundation or its licensors,
005:         * as applicable.
006:         * 
007:         * Licensed under the Apache License, Version 2.0 (the "License");
008:         * you may not use this file except in compliance with the License.
009:         * You may obtain a copy of the License at
010:         * 
011:         *      http://www.apache.org/licenses/LICENSE-2.0
012:         * 
013:         * Unless required by applicable law or agreed to in writing, software
014:         * distributed under the License is distributed on an "AS IS" BASIS,
015:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016:         * See the License for the specific language governing permissions and
017:         * limitations under the License.
018:         */
019:
020:        package com.sun.org.apache.xml.internal.resolver;
021:
022:        import java.util.Hashtable;
023:        import java.util.Vector;
024:
025:        /**
026:         * Represents a Catalog entry.
027:         *
028:         * <p>Instances of this class represent individual entries
029:         * in a Catalog.</p>
030:         *
031:         * <p>Each catalog entry has a unique name and is associated with
032:         * an arbitrary number of arguments (all strings). For example, the
033:         * TR9401 catalog entry "PUBLIC" has two arguments, a public identifier
034:         * and a system identifier. Each entry has a unique numeric type,
035:         * assigned automatically when the entry type is created.</p>
036:         *
037:         * <p>The number and type of catalog entries is maintained
038:         * <em>statically</em>. Catalog classes, or their subclasses, can add
039:         * new entry types, but all Catalog objects share the same global pool
040:         * of types.</p>
041:         *
042:         * <p>Initially there are no valid entries.</p>
043:         *
044:         * @see Catalog
045:         *
046:         * @author Norman Walsh
047:         * <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
048:         *
049:         * @version 1.0
050:         */
051:        public class CatalogEntry {
052:            /** The nextEntry is the ordinal number of the next entry type. */
053:            protected static int nextEntry = 0;
054:
055:            /**
056:             * The entryTypes vector maps catalog entry names
057:             * (e.g., 'BASE' or 'SYSTEM') to their type (1, 2, etc.).
058:             * Names are case sensitive.
059:             */
060:            protected static Hashtable entryTypes = new Hashtable();
061:
062:            /** The entryTypes vector maps catalog entry types to the
063:                number of arguments they're required to have. */
064:            protected static Vector entryArgs = new Vector();
065:
066:            /**
067:             * Adds a new catalog entry type.
068:             *
069:             * @param name The name of the catalog entry type. This must be
070:             * unique among all types and is case-sensitive. (Adding a duplicate
071:             * name effectively replaces the old type with the new type.)
072:             * @param numArgs The number of arguments that this entry type
073:             * is required to have. There is no provision for variable numbers
074:             * of arguments.
075:             * @return The type for the new entry.
076:             */
077:            public static int addEntryType(String name, int numArgs) {
078:                entryTypes.put(name, new Integer(nextEntry));
079:                entryArgs.add(nextEntry, new Integer(numArgs));
080:                nextEntry++;
081:
082:                return nextEntry - 1;
083:            }
084:
085:            /**
086:             * Lookup an entry type
087:             *
088:             * @param name The name of the catalog entry type.
089:             * @return The type of the catalog entry with the specified name.
090:             * @throws InvalidCatalogEntryTypeException if no entry has the
091:             * specified name.
092:             */
093:            public static int getEntryType(String name) throws CatalogException {
094:                if (!entryTypes.containsKey(name)) {
095:                    throw new CatalogException(
096:                            CatalogException.INVALID_ENTRY_TYPE);
097:                }
098:
099:                Integer iType = (Integer) entryTypes.get(name);
100:
101:                if (iType == null) {
102:                    throw new CatalogException(
103:                            CatalogException.INVALID_ENTRY_TYPE);
104:                }
105:
106:                return iType.intValue();
107:            }
108:
109:            /**
110:             * Find out how many arguments an entry is required to have.
111:             *
112:             * @param name The name of the catalog entry type.
113:             * @return The number of arguments that entry type is required to have.
114:             * @throws InvalidCatalogEntryTypeException if no entry has the
115:             * specified name.
116:             */
117:            public static int getEntryArgCount(String name)
118:                    throws CatalogException {
119:                return getEntryArgCount(getEntryType(name));
120:            }
121:
122:            /**
123:             * Find out how many arguments an entry is required to have.
124:             *
125:             * @param type A valid catalog entry type.
126:             * @return The number of arguments that entry type is required to have.
127:             * @throws InvalidCatalogEntryTypeException if the type is invalid.
128:             */
129:            public static int getEntryArgCount(int type)
130:                    throws CatalogException {
131:                try {
132:                    Integer iArgs = (Integer) entryArgs.get(type);
133:                    return iArgs.intValue();
134:                } catch (ArrayIndexOutOfBoundsException e) {
135:                    throw new CatalogException(
136:                            CatalogException.INVALID_ENTRY_TYPE);
137:                }
138:            }
139:
140:            /** The entry type of this entry */
141:            protected int entryType = 0;
142:
143:            /** The arguments associated with this entry */
144:            protected Vector args = null;
145:
146:            /**
147:             * Null constructor; something for subclasses to call.
148:             */
149:            public CatalogEntry() {
150:            }
151:
152:            /**
153:             * Construct a catalog entry of the specified type.
154:             *
155:             * @param name The name of the entry type
156:             * @param args A String Vector of arguments
157:             * @throws InvalidCatalogEntryTypeException if no such entry type
158:             * exists.
159:             * @throws InvalidCatalogEntryException if the wrong number of arguments
160:             * is passed.
161:             */
162:            public CatalogEntry(String name, Vector args)
163:                    throws CatalogException {
164:                Integer iType = (Integer) entryTypes.get(name);
165:
166:                if (iType == null) {
167:                    throw new CatalogException(
168:                            CatalogException.INVALID_ENTRY_TYPE);
169:                }
170:
171:                int type = iType.intValue();
172:
173:                try {
174:                    Integer iArgs = (Integer) entryArgs.get(type);
175:                    if (iArgs.intValue() != args.size()) {
176:                        throw new CatalogException(
177:                                CatalogException.INVALID_ENTRY);
178:                    }
179:                } catch (ArrayIndexOutOfBoundsException e) {
180:                    throw new CatalogException(
181:                            CatalogException.INVALID_ENTRY_TYPE);
182:                }
183:
184:                entryType = type;
185:                this .args = args;
186:            }
187:
188:            /**
189:             * Construct a catalog entry of the specified type.
190:             *
191:             * @param type The entry type
192:             * @param args A String Vector of arguments
193:             * @throws InvalidCatalogEntryTypeException if no such entry type
194:             * exists.
195:             * @throws InvalidCatalogEntryException if the wrong number of arguments
196:             * is passed.
197:             */
198:            public CatalogEntry(int type, Vector args) throws CatalogException {
199:                try {
200:                    Integer iArgs = (Integer) entryArgs.get(type);
201:                    if (iArgs.intValue() != args.size()) {
202:                        throw new CatalogException(
203:                                CatalogException.INVALID_ENTRY);
204:                    }
205:                } catch (ArrayIndexOutOfBoundsException e) {
206:                    throw new CatalogException(
207:                            CatalogException.INVALID_ENTRY_TYPE);
208:                }
209:
210:                entryType = type;
211:                this .args = args;
212:            }
213:
214:            /**
215:             * Get the entry type.
216:             *
217:             * @return The entry type of the CatalogEntry
218:             */
219:            public int getEntryType() {
220:                return entryType;
221:            }
222:
223:            /**
224:             * Get an entry argument.
225:             *
226:             * @param argNum The argument number (arguments are numbered from 0).
227:             * @return The specified argument or null if an invalid argNum is
228:             * provided.
229:             */
230:            public String getEntryArg(int argNum) {
231:                try {
232:                    String arg = (String) args.get(argNum);
233:                    return arg;
234:                } catch (ArrayIndexOutOfBoundsException e) {
235:                    return null;
236:                }
237:            }
238:
239:            /**
240:             * Set an entry argument.
241:             *
242:             * <p>Catalogs sometimes need to adjust the catlog entry parameters,
243:             * for example to make a relative URI absolute with respect to the
244:             * current base URI. But in general, this function should only be
245:             * called shortly after object creation to do some sort of cleanup.
246:             * Catalog entries should not mutate over time.</p>
247:             *
248:             * @param argNum The argument number (arguments are numbered from 0).
249:             * @throws ArrayIndexOutOfBoundsException if an invalid argument
250:             * number is provided.
251:             */
252:            public void setEntryArg(int argNum, String newspec)
253:                    throws ArrayIndexOutOfBoundsException {
254:                args.set(argNum, newspec);
255:            }
256:        }
ww___w.j___a__v__a_2__s__._c__o_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.