Source Code Cross Referenced for TaggedComponentList.java in  » Collaboration » JacORB » org » jacorb » orb » 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 » Collaboration » JacORB » org.jacorb.orb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jacorb.orb;
002:
003:        import java.lang.reflect.*;
004:        import java.util.*;
005:
006:        import org.omg.IOP.*;
007:
008:        /**
009:         * Represents a list of tagged components from an IOR, along with some
010:         * generic methods to find and access individual components.
011:         * <p>
012:         * @author Andre Spiegel
013:         * @version $Id: TaggedComponentList.java,v 1.8 2006/06/27 10:50:53 alphonse.bendt Exp $
014:         */
015:        public class TaggedComponentList implements  Cloneable {
016:            private TaggedComponent[] components = null;
017:
018:            /**
019:             * Constructs a TaggedComponentList object from a CDR representation
020:             * of an array of tagged components.
021:             */
022:            public TaggedComponentList(org.omg.CORBA.portable.InputStream in) {
023:                components = TaggedComponentSeqHelper.read(in);
024:            }
025:
026:            /**
027:             * Constructs a TaggedComponentList from a CDR encapsulation of
028:             * an array of tagged components.
029:             */
030:            public TaggedComponentList(byte[] data) {
031:                CDRInputStream in = new CDRInputStream(null, data);
032:                in.openEncapsulatedArray();
033:                components = TaggedComponentSeqHelper.read(in);
034:            }
035:
036:            /**
037:             * Constructs a new, empty TaggedComponentList.
038:             */
039:            public TaggedComponentList() {
040:                components = new TaggedComponent[0];
041:            }
042:
043:            public int size() {
044:                return components.length;
045:            }
046:
047:            public boolean isEmpty() {
048:                return components.length == 0;
049:            }
050:
051:            public TaggedComponent get(int index) {
052:                return components[index];
053:            }
054:
055:            public Object clone() throws CloneNotSupportedException {
056:                TaggedComponentList result = (TaggedComponentList) super 
057:                        .clone();
058:                result.components = new TaggedComponent[this .components.length];
059:                for (int i = 0; i < this .components.length; i++) {
060:                    result.components[i] = new TaggedComponent(
061:                            this .components[i].tag,
062:                            new byte[this .components[i].component_data.length]);
063:                    System.arraycopy(this .components[i].component_data, 0,
064:                            result.components[i].component_data, 0,
065:                            this .components[i].component_data.length);
066:                }
067:                return result;
068:            }
069:
070:            public TaggedComponent[] asArray() {
071:                return components;
072:            }
073:
074:            /**
075:             * Adds a tagged component to this list. The component's data
076:             * is created by marshaling the given data Object using the
077:             * write() method of the given helper class.
078:             */
079:            public void addComponent(int tag, Object data, Class helper) {
080:                try {
081:                    Method writeMethod = helper.getMethod("write", new Class[] {
082:                            org.omg.CORBA.portable.OutputStream.class,
083:                            data.getClass() });
084:
085:                    final CDROutputStream out = new CDROutputStream();
086:
087:                    try {
088:                        out.beginEncapsulatedArray();
089:                        writeMethod.invoke(null, new Object[] { out, data });
090:                        addComponent(tag, out.getBufferCopy());
091:                    } finally {
092:                        out.close();
093:                    }
094:                } catch (NoSuchMethodException ex) {
095:                    throw new RuntimeException("Helper " + helper.getName()
096:                            + " has no appropriate write() method.");
097:                } catch (IllegalAccessException ex) {
098:                    throw new RuntimeException(
099:                            "Cannot access write() method of helper "
100:                                    + helper.getName());
101:                } catch (InvocationTargetException ex) {
102:                    throw new RuntimeException(
103:                            "Exception while marshaling component data: "
104:                                    + ex.getTargetException());
105:                }
106:            }
107:
108:            /**
109:             * Adds a tagged component to this list.
110:             */
111:            public void addComponent(int tag, byte[] data) {
112:                addComponent(new TaggedComponent(tag, data));
113:            }
114:
115:            /**
116:             * Adds a tagged component to this list.
117:             */
118:            public void addComponent(TaggedComponent component) {
119:                TaggedComponent[] newComponents = new TaggedComponent[components.length + 1];
120:                System.arraycopy(components, 0, newComponents, 0,
121:                        components.length);
122:                newComponents[components.length] = component;
123:                components = newComponents;
124:            }
125:
126:            /**
127:             * Adds an entire TaggedComponentList to this list.
128:             */
129:            public void addAll(TaggedComponentList other) {
130:                TaggedComponent[] newComponents = new TaggedComponent[components.length
131:                        + other.components.length];
132:                System.arraycopy(components, 0, newComponents, 0,
133:                        components.length);
134:                System.arraycopy(other.components, 0, newComponents,
135:                        components.length, other.components.length);
136:                components = newComponents;
137:            }
138:
139:            /**
140:             * Searches for a component with the given tag in this component list.
141:             * If one is found, this method reads the corresponding data with the given
142:             * helper class, and returns the resulting object, otherwise returns
143:             * null.
144:             */
145:            public Object getComponent(int tag, Class helper) {
146:                for (int i = 0; i < components.length; i++) {
147:                    if (components[i].tag == tag) {
148:                        return getComponentData(components[i].component_data,
149:                                helper);
150:                    }
151:                }
152:                return null;
153:            }
154:
155:            /**
156:             * Returns the first component with the given tag, which is assumed
157:             * to be a CDR string.  If no component with the given tag exists,
158:             * returns null.
159:             */
160:            public String getStringComponent(int tag) {
161:                for (int i = 0; i < components.length; i++) {
162:                    if (components[i].tag == tag) {
163:                        final CDRInputStream in = new CDRInputStream(null,
164:                                components[i].component_data);
165:
166:                        try {
167:                            in.openEncapsulatedArray();
168:                            return in.read_string();
169:                        } finally {
170:                            in.close();
171:                        }
172:                    }
173:                }
174:                return null;
175:            }
176:
177:            /**
178:             * Returns a List of all components with the given tag from this
179:             * TaggedComponentList.  Each individual component is read with
180:             * the given helper class.  If no components with the given tag
181:             * can be found, an empty list is returned.
182:             */
183:            public List getComponents(int tag, Class helper) {
184:                List result = new ArrayList();
185:                for (int i = 0; i < components.length; i++) {
186:                    if (components[i].tag == tag) {
187:                        result.add(getComponentData(
188:                                components[i].component_data, helper));
189:                    }
190:                }
191:                return result;
192:            }
193:
194:            /**
195:             * Uses the given helper class to read a CDR-encapsulated component_data
196:             * field from the given byte array, data.
197:             */
198:            private Object getComponentData(byte[] data, Class helper) {
199:                try {
200:                    Method readMethod = helper
201:                            .getMethod(
202:                                    "read",
203:                                    new Class[] { org.omg.CORBA.portable.InputStream.class });
204:                    final CDRInputStream in = new CDRInputStream(null, data);
205:
206:                    try {
207:                        in.openEncapsulatedArray();
208:                        return readMethod.invoke(null, new Object[] { in });
209:                    } finally {
210:                        in.close();
211:                    }
212:                } catch (NoSuchMethodException ex) {
213:                    throw new RuntimeException("Helper " + helper.getName()
214:                            + " has no appropriate read() method.");
215:                } catch (IllegalAccessException ex) {
216:                    throw new RuntimeException(
217:                            "Cannot access read() method of helper "
218:                                    + helper.getName());
219:                } catch (InvocationTargetException ex) {
220:                    throw new RuntimeException(
221:                            "Exception while reading component data: "
222:                                    + ex.getTargetException());
223:                }
224:            }
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.