|
From: Michael R. <mr...@us...> - 2004-08-09 10:06:20
|
Update of /cvsroot/openorb/OpenORB/src/test/org/openorb/orb/test/iiop/fragmentedmessage In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31977/src/test/org/openorb/orb/test/iiop/fragmentedmessage Added Files: AttributeData.xml AttributeManagerImpl.java FragmentedMessageTest.java LocalContentHandler.java ObjectIdImpl.java package.html Log Message: Added the fragmented test case from Michael Macaluso --- NEW FILE: AttributeData.xml --- <?xml version="1.0" encoding="UTF-8"?> <!-- This is the test data for the fragmented message test. --> <AttributeData> <AttributeDefinition ID="28" Name="Outline" TSCounter="2"> <AttributeType ID="1" Code="Ab" Name="Boolean" TSCounter="0" /> </AttributeDefinition> <AttributeDefinition ID="135" Name="UPSable" TSCounter="0"> <AttributeType ID="1" Code="Ab" Name="Boolean" TSCounter="0" /> </AttributeDefinition> <AttributeDefinition ID="182" Name="Ready for PPF" TSCounter="0"> <AttributeType ID="1" Code="Ab" Name="Boolean" TSCounter="0" /> </AttributeDefinition> <AttributeDefinition ID="186" Name="Release Route" TSCounter="0"> <AttributeType ID="1" Code="Ab" Name="Boolean" TSCounter="0" /> </AttributeDefinition> <AttributeDefinition ID="241" Name="Web Ready" TSCounter="0"> <AttributeType ID="1" Code="Ab" Name="Boolean" TSCounter="0" /> [...19969 lines suppressed...] <AttributeDefinition ID="6890" Name="Olympic Uniforms Cost Source" TSCounter="0"> <AttributeType ID="783" Code="Ae" Name="Ae" TSCounter="1" /> </AttributeDefinition> <AttributeDefinition ID="6891" Name="Waddell Co Inc Cost Source" TSCounter="0"> <AttributeType ID="784" Code="Ae" Name="Ae" TSCounter="1" /> </AttributeDefinition> <AttributeDefinition ID="6892" Name="Royal Seating Corp Cost Source" TSCounter="0"> <AttributeType ID="785" Code="Ae" Name="Ae" TSCounter="1" /> </AttributeDefinition> <AttributeDefinition ID="6903" Name="Tee Jay's Apperal Inc Cost Source" TSCounter="0"> <AttributeType ID="786" Code="Ae" Name="Ae" TSCounter="1" /> </AttributeDefinition> <AttributeDefinition ID="6914" Name="Installnet Int'l Inc Cost Source" TSCounter="0"> <AttributeType ID="787" Code="Ae" Name="Ae" TSCounter="1" /> </AttributeDefinition> <AttributeDefinition ID="6925" Name="Mirow Int'l Cost Source" TSCounter="0"> <AttributeType ID="788" Code="Ae" Name="Ae" TSCounter="1" /> </AttributeDefinition> </AttributeData> --- NEW FILE: AttributeManagerImpl.java --- /* * Copyright (C) The Community OpenORB Project. All rights reserved. * * This software is published under the terms of The OpenORB Community Software * License version 1.0, a copy of which has been included with this distribution * in the LICENSE.txt file. */ package org.openorb.orb.test.iiop.fragmentedmessage; import org.omg.PortableServer.POA; import java.util.List; import java.util.LinkedList; import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParser; /** * @author Michael Macaluso */ public class AttributeManagerImpl extends AttributeManagerPOA { private AttributeDefinition[] m_attributeDefinitions; private POA m_poa; AttributeManagerImpl( POA aPOA ) { m_poa = aPOA; } public POA _default_POA() { return m_poa; } /** * Operation getAttributeDefinitions */ public AttributeDefinition[] getAttributeDefinitions() { if ( null == m_attributeDefinitions ) { List anAttributeDefinitionsList = new LinkedList(); // Use an instance of ourselves as the SAX event handler LocalContentHandler aLocalContentHandler = new LocalContentHandler( anAttributeDefinitionsList, _orb() ); // Use the default (non-validating) parser SAXParserFactory aSAXParserFactory = SAXParserFactory.newInstance(); try { // Parse the input SAXParser aSAXParser = aSAXParserFactory.newSAXParser(); aSAXParser.parse( FragmentedMessageTest.class.getResourceAsStream( "AttributeData.xml" ), aLocalContentHandler ); } catch ( Throwable t ) { t.printStackTrace(); } m_attributeDefinitions = (AttributeDefinition[]) anAttributeDefinitionsList.toArray( new AttributeDefinition[ anAttributeDefinitionsList.size() ] ); } return m_attributeDefinitions; } } --- NEW FILE: FragmentedMessageTest.java --- /* * Copyright (C) The Community OpenORB Project. All rights reserved. * * This software is published under the terms of The OpenORB Community Software * License version 1.0, a copy of which has been included with this distribution * in the LICENSE.txt file. */ package org.openorb.orb.test.iiop.fragmentedmessage; import junit.framework.TestSuite; import org.omg.PortableServer.POA; import org.openorb.orb.test.ORBTestCase; import org.omg.CORBA.ORB; import java.util.Properties; /** * Tests marshaling and unmarshaling of various iiop types. * * @author Michael Macaluso */ public class FragmentedMessageTest extends ORBTestCase { private AttributeManager m_serverReference; private AttributeManager m_clientReference; /** * Constructor. * * @param name The name of the test case. */ public FragmentedMessageTest( String name ) { super( name ); } /** * Set up the test case. */ protected void setUp() { Properties aProperties = new Properties(); aProperties.put( "org.omg.CORBA.ORBClass", "org.openorb.orb.core.ORB" ); aProperties.put( "org.omg.CORBA.ORBSingletonClass", "org.openorb.orb.core.ORBSingleton" ); super.setUp( aProperties ); try { ORB anORB = getORB(); POA rootPOA = ( POA ) anORB.resolve_initial_references( "RootPOA" ); AttributeManager m_ServerReference = ( new AttributeManagerImpl( rootPOA ) )._this( anORB ); rootPOA.the_POAManager().activate(); m_clientReference = AttributeManagerHelper.narrow( forceMarshal( m_ServerReference ) ); } catch ( org.omg.CORBA.UserException ex ) { fail( "exception during setup:" + ex.toString() ); } } /** * Simple struct echo. */ public void testGetAttributeDefinitions() { System.out.println( "Test: " + this.getClass().getName() + ".testGetAttributeDefinitions" ); AttributeDefinition[] anAttributeDefinitionArray = m_clientReference.getAttributeDefinitions(); } /** * The entry point of the test case. * * @param args The command line arguments. */ public static void main( String[] args ) { System.out.println( "Executing the " + FragmentedMessageTest.class.getName() + "..." ); junit.textui.TestRunner.run( new TestSuite( FragmentedMessageTest.class ) ); } } --- NEW FILE: LocalContentHandler.java --- /* * Copyright (C) The Community OpenORB Project. All rights reserved. * * This software is published under the terms of The OpenORB Community Software * License version 1.0, a copy of which has been included with this distribution * in the LICENSE.txt file. */ package org.openorb.orb.test.iiop.fragmentedmessage; import org.omg.CORBA.ORB; import org.xml.sax.helpers.DefaultHandler; /** * Class responsible for parsing the XML file correctly and * adding the newly created objects to a provided collection. * * @author Michael Macaluso */ public class LocalContentHandler extends DefaultHandler { public static final java.util.Map ATTRIBUTE_TYPECODE2ATTRIBUTE_ENUM_MAP = new java.util.HashMap(); public static final String STRING_ATTRIBUTE = "As"; public static final String DIMENSION_ATTRIBUTE = "Ai"; public static final String DOUBLE_ATTRIBUTE = "Ad"; public static final String BOOLEAN_ATTRIBUTE = "Ab"; public static final String LONG_ATTRIBUTE = "Al"; public static final String DATE_ATTRIBUTE = "Aa"; public static final String DATETIME_ATTRIBUTE = "At"; public static final String ENUMERATION_ATTRIBUTE = "Ae"; public static final String USERLIST_ATTRIBUTE = "Aw"; public static final String SEQUENCE_ATTRIBUTE = "Aq"; public static final String STRINGBUFFER_ATTRIBUTE = "Au"; public static final String STYLEDTEXT_ATTRIBUTE = "YT"; static { ATTRIBUTE_TYPECODE2ATTRIBUTE_ENUM_MAP.put( STRING_ATTRIBUTE, AttributeEnum.StringAttr ); ATTRIBUTE_TYPECODE2ATTRIBUTE_ENUM_MAP.put( DIMENSION_ATTRIBUTE, AttributeEnum.Dimension ); ATTRIBUTE_TYPECODE2ATTRIBUTE_ENUM_MAP.put( DOUBLE_ATTRIBUTE, AttributeEnum.DoubleAttr ); ATTRIBUTE_TYPECODE2ATTRIBUTE_ENUM_MAP.put( BOOLEAN_ATTRIBUTE, AttributeEnum.BooleanAttr ); ATTRIBUTE_TYPECODE2ATTRIBUTE_ENUM_MAP.put( LONG_ATTRIBUTE, AttributeEnum.LongAttr ); ATTRIBUTE_TYPECODE2ATTRIBUTE_ENUM_MAP.put( DATE_ATTRIBUTE, AttributeEnum.DateAttr ); ATTRIBUTE_TYPECODE2ATTRIBUTE_ENUM_MAP.put( DATETIME_ATTRIBUTE, AttributeEnum.DateTime ); ATTRIBUTE_TYPECODE2ATTRIBUTE_ENUM_MAP.put( ENUMERATION_ATTRIBUTE, AttributeEnum.Enumerated ); ATTRIBUTE_TYPECODE2ATTRIBUTE_ENUM_MAP.put( USERLIST_ATTRIBUTE, AttributeEnum.UserList ); ATTRIBUTE_TYPECODE2ATTRIBUTE_ENUM_MAP.put( SEQUENCE_ATTRIBUTE, AttributeEnum.SequenceAttr ); ATTRIBUTE_TYPECODE2ATTRIBUTE_ENUM_MAP.put( STRINGBUFFER_ATTRIBUTE, AttributeEnum.StringBuffer ); ATTRIBUTE_TYPECODE2ATTRIBUTE_ENUM_MAP.put( STYLEDTEXT_ATTRIBUTE, AttributeEnum.StyledText ); } private final java.util.Collection m_collectionOfAttributeDefintions; private final ORB m_orb; private AttributeDefinition m_attributeDefinition; private boolean m_inAttributeData = false; private boolean m_inAttributeDefinition = false; public LocalContentHandler( java.util.Collection aCollectionOfAttributeDefintions, ORB anORB ) { m_collectionOfAttributeDefintions = aCollectionOfAttributeDefintions; m_orb = anORB; } public void startElement( String namespaceURI, String localName, String qName, org.xml.sax.Attributes atts ) throws org.xml.sax.SAXException { if ( !m_inAttributeData ) { if ( qName.equalsIgnoreCase( "AttributeData" ) ) { m_inAttributeData = true; return; } } if ( m_attributeDefinition == null ) { if ( qName.equalsIgnoreCase( "AttributeDefinition" ) ) { m_inAttributeDefinition = true; m_attributeDefinition = new AttributeDefinition(); int index; index = atts.getIndex( "ID" ); m_attributeDefinition.id = atts.getValue( index ); index = atts.getIndex( "Name" ); m_attributeDefinition.name = atts.getValue( index ); index = atts.getIndex( "TSCounter" ); try { m_attributeDefinition.tsCounter = Integer.parseInt( atts.getValue( index ) ); } catch ( NumberFormatException e ) { e.printStackTrace(); } m_attributeDefinition.moreInfo = m_orb.create_any(); index = atts.getIndex( "Value" ); if ( -1 != index ) { try { m_attributeDefinition.moreInfo.insert_long( Integer.parseInt( atts.getValue( index ) ) ); } catch ( NumberFormatException e ) { e.printStackTrace(); } } // hard-coded attributes m_attributeDefinition.status = ItemStatus.UNMODIFIED; m_attributeDefinition.uiDefinition = new AttributeConstraint[ 0 ]; m_collectionOfAttributeDefintions.add( m_attributeDefinition ); return; } } else { AttributeType anAttributeType = new AttributeType(); int index; index = atts.getIndex( "ID" ); anAttributeType.id = new ObjectIdImpl( atts.getValue( index ) ); index = atts.getIndex( "Name" ); anAttributeType.name = atts.getValue( index ); index = atts.getIndex( "Code" ); String anAttributeEnumCode = atts.getValue( index ); anAttributeType.type = ( AttributeEnum ) ATTRIBUTE_TYPECODE2ATTRIBUTE_ENUM_MAP.get( anAttributeEnumCode ); index = atts.getIndex( "TSCounter" ); try { anAttributeType.tsCounter = Integer.parseInt( atts.getValue( index ) ); } catch ( NumberFormatException e ) { e.printStackTrace(); } // hard-coded attributes anAttributeType.constraints = new AttributeConstraint[0]; m_attributeDefinition.type = anAttributeType; m_attributeDefinition = null; } } } --- NEW FILE: ObjectIdImpl.java --- /* * Copyright (C) The Community OpenORB Project. All rights reserved. * * This software is published under the terms of The OpenORB Community Software * License version 1.0, a copy of which has been included with this distribution * in the LICENSE.txt file. */ package org.openorb.orb.test.iiop.fragmentedmessage; /** * @author Michael Macaluso */ public final class ObjectIdImpl extends ObjectId implements Comparable { public static final int NULL_HASHCODE = -1; public ObjectIdImpl() { } public ObjectIdImpl( String id ) { objectid = id; } public void marshal( org.omg.CORBA.DataOutputStream os ) { boolean isNull = ( null == objectid ); os.write_boolean( isNull ); if ( !isNull ) { os.write_wstring( objectid ); } } public void unmarshal( org.omg.CORBA.DataInputStream is ) { boolean isNull = is.read_boolean(); if ( isNull ) { objectid = null; } else { objectid = is.read_wstring(); } } public boolean equals( Object anObject ) { if ( null == anObject ) { return false; } Class aClass = anObject.getClass(); if ( aClass == ObjectIdImpl.class ) { return equals( ( ObjectIdImpl ) anObject ); } else if ( aClass == String.class ) { return equals( ( String ) anObject ); } return false; } public boolean equals( ObjectIdImpl anObject ) { if ( null == anObject ) { return false; } return equals( anObject.objectid ); } public boolean equals( String anObject ) { if ( null == anObject ) { return ( objectid == null ); } return anObject.equals( objectid ); } public int hashCode() { if ( null == objectid ) { return NULL_HASHCODE; } else { return objectid.hashCode(); } } public int compare( Object anObject ) { return compareTo( anObject ); } public int compareTo( Object anObject ) { if ( null == anObject ) { return -1; } Class aClass = anObject.getClass(); if ( aClass == ObjectIdImpl.class ) { return compareTo( ( ObjectIdImpl ) anObject ); } else if ( aClass == String.class ) { return compareTo( ( String ) anObject ); } return -1; } public int compareTo( ObjectIdImpl anObject ) { if ( null == anObject ) { return -1; } return compareTo( anObject.objectid ); } public int compareTo( String anObject ) { if ( null == anObject ) { if ( null == objectid ) { return 0; } else { return -1; } } else { if ( null == objectid ) { return 1; } else { return objectid.compareTo( anObject ); } } } public String toString() { return objectid; } } --- NEW FILE: package.html --- <body> <p> IIOP test case to create multiple large fragments. </p> </body> |