Source Code Cross Referenced for TaxonomyNode.java in  » Portal » Open-Portal » soif » 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 » Portal » Open Portal » soif 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
003:         *  NETSCAPE COMMUNICATIONS CORPORATION
004:         *
005:         *  Copyright (c) 1996 Netscape Communications Corporation.
006:         *  All Rights Reserved.
007:         *  Use of this Source Code is subject to the terms of the applicable
008:         *  license agreement from Netscape Communications Corporation.
009:         */
010:
011:        package soif;
012:
013:        import util.ReportError;
014:
015:        /**
016:         Represent nodes in the taxonomy.
017:         *
018:         */
019:        public class TaxonomyNode {
020:            /* short cut vars */
021:            private String id;
022:            private String parentId;
023:            private String label;
024:
025:            private AVPairs list;
026:
027:            /*--------------*/
028:            /* constructors */
029:            /*--------------*/
030:
031:            /**
032:             * Constructor.
033:             * @param id id
034:             * @param parentId parent id
035:             * @param taxonomyId taxonomy id
036:             * @param description description
037:             * @exception IllegalArgumentException on null id
038:             */
039:            public TaxonomyNode(String id, String parentId, String taxonomyId,
040:                    String description) {
041:                if (id == null) {
042:                    throw new IllegalArgumentException(
043:                            "classification id cannot be null");
044:                }
045:                insert("id", id);
046:                insert("parent-id", parentId);
047:                insert("taxonomy-id", taxonomyId);
048:                insert("description", description);
049:
050:                setLabel();
051:
052:                if (parentId != null) {
053:                    if ((parentId.compareTo("ROOT") != 0)
054:                            && (id.substring(0, parentId.length()).compareTo(
055:                                    parentId) != 0)) {
056:                        ReportError.reportError(ReportError.INTERNAL,
057:                                "TaxonomyNode", "TaxonomyNode",
058:                                Messages.TAXIDPARENTMISMATCH);
059:                        System.out.println(toString());
060:                    }
061:                }
062:            }
063:
064:            /**
065:             * Constructor.
066:             * @param soif soif chunk
067:             * @exception IllegalArgumentException on null id
068:             */
069:            public TaxonomyNode(SOIF soif) {
070:                id = soif.getValue("Id");
071:                if (id == null) {
072:                    throw new IllegalArgumentException(
073:                            "classification id cannot be null");
074:                }
075:                parentId = soif.getValue("Parent-Id");
076:                list = soif.list;
077:                setLabel();
078:            }
079:
080:            /**
081:             * Set the label to be printed on the diagram node.
082:             */
083:            public void setLabel() {
084:                if (parentId == null) {
085:                    return;
086:                }
087:                if (parentId.length() == 0) {
088:                    return;
089:                }
090:
091:                if (id.length() > 0) {
092:                    if ("ROOT".compareTo(parentId) == 0) {
093:                        label = id;
094:                    } else {
095:                        // System.out.println( "p [" + parentId + "]" );
096:                        // System.out.println( "i [" + id + "]" );
097:                        label = id.substring((parentId.length() + 1), id
098:                                .length());
099:                    }
100:                } else {
101:                    label = "";
102:                }
103:            }
104:
105:            /**
106:             * Return the label.
107:             */
108:            public String getLabel() {
109:                return label;
110:            }
111:
112:            /**
113:             * Return the id.
114:             */
115:            public String getId() {
116:                return id;
117:            }
118:
119:            /**
120:             * Return the parent id.
121:             */
122:            public String getParentId() {
123:                return parentId;
124:            }
125:
126:            /**
127:             * Get value by attribute.
128:             * Ignores case of attribute name.
129:             * @param s the attribute
130:             */
131:            public String getValue(String s) {
132:                return list.getValue(s);
133:            }
134:
135:            /**
136:             * Set value by attribute.
137:             * Ignores case of attribute name.
138:             * Note that it is possible to set id, taxonomyid
139:             * and parentid here.
140:             * However, because this information is significant
141:             * to other nodes in the tree, this isn't really
142:             * recommended.
143:             * Safer methods will eventually be provided and
144:             * use of this method may be restricted to non id
145:             * attributes.
146:             * <p>
147:             * Note that in certain cases this setValue recurses
148:             * and that the boolean success value only refers
149:             * the the success of the principal and not the
150:             * secondary setValue()s.
151:             * In this context the secondary setValue() calls
152:             * reference an AVPair which must exist for the
153:             * TaxonomyNode so this is not an issue.
154:             * @param s the attribute
155:             * @param v the value
156:             */
157:            public boolean setValue(String s, String v) {
158:                if ("Id".equalsIgnoreCase(s)) {
159:                    id = v;
160:                    setLabel();
161:                }
162:                if ("Parent-Id".equalsIgnoreCase(s)) {
163:                    parentId = v;
164:                    if ("ROOT".compareTo(v) == 0) {
165:                        setValue("Id", label);
166:                    } else {
167:                        setValue("Id", v + ":" + label);
168:                    }
169:                }
170:
171:                return list.setValue(s, v);
172:            }
173:
174:            /**
175:             * Inserts a new AVPairs instance.
176:             * The inserter of duplicates (particular of
177:             * key attributes) is assumed to know what they're doing.
178:             * @param att the attribute
179:             * @param val the value
180:             */
181:            public void insert(String att, String val) {
182:                if (list == null) {
183:                    list = new AVPairs(att, val);
184:                } else {
185:                    list.insertAfter(new AVPairs(att, val));
186:                }
187:
188:                if ("id".equalsIgnoreCase(att) == true) {
189:                    id = val;
190:                    setLabel();
191:                }
192:                if ("Parent-Id".equalsIgnoreCase(att) == true) {
193:                    parentId = val;
194:                    setLabel();
195:                }
196:            }
197:
198:            /**
199:             * Remove AVPair by attribute.
200:             * Ignores case of attribute name.
201:             * @param s the attribute
202:             */
203:            public void remove(String s) {
204:                list = list.remove(list.getAVPair(s));
205:                if ("id".equalsIgnoreCase(s) == true) {
206:                    id = "";
207:                    setLabel();
208:                }
209:                if ("Parent-Id".equalsIgnoreCase(s) == true) {
210:                    parentId = "";
211:                    setLabel();
212:                }
213:            }
214:
215:            /**
216:             * A convenience method which bundles insert(),
217:             * setValue() and remove().
218:             * If the proposed value is length 0, remove() is called.
219:             * Otherwise, setValue() is called.
220:             * If setValue() fails, insertAfter() is called.
221:             * @param att attribute
222:             * @param val value
223:             */
224:            public void update(String att, String val) {
225:                list = list.update(att, val);
226:            }
227:
228:            /**
229:             * Return SOIF.
230:             */
231:            public String toSOIF() {
232:                StringBuffer sb = new StringBuffer();
233:
234:                sb.append("@"
235:                        + (String) ((parentId == null) ? "TAXONOMY"
236:                                : ((parentId.length() == 0) ? "TAXONOMY"
237:                                        : "CLASSIFICATION")) + " { -\n");
238:                sb.append(list.toSOIFList());
239:                sb.append("\n}\n");
240:
241:                return sb.toString();
242:            }
243:
244:            public String toString() {
245:                return "TaxonomyNode instance: (" + Header.VERSION + ")\n"
246:                        + "\tparentId\t= [" + parentId + "]\n" + "\tid\t= ["
247:                        + id + "]\n" + "\tlabel\t= [" + label + "]\n"
248:                        + "\tlist\t= [" + list.toString() + "]\n" + ")\n";
249:            }
250:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.