You are viewing a plain text version of this content. The canonical link for it is here.
Posted to yoko-commits@incubator.apache.org by dm...@apache.org on 2006/06/13 19:40:52 UTC
svn commit: r413964 [3/3] - in /incubator/yoko/trunk/bindings: ./
src/main/java/org/apache/yoko/bindings/corba/
src/main/java/org/apache/yoko/bindings/corba/extensions/
Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaTypesExtensionHelper.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaTypesExtensionHelper.java?rev=413964&view=auto
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaTypesExtensionHelper.java (added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaTypesExtensionHelper.java Tue Jun 13 12:40:51 2006
@@ -0,0 +1,349 @@
+/**
+*
+* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.yoko.bindings.corba.extensions;
+
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.ExtensionDeserializer;
+import javax.wsdl.extensions.ExtensionRegistry;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.apache.schemas.yoko.bindings.corba.Alias;
+import org.apache.schemas.yoko.bindings.corba.Anonarray;
+import org.apache.schemas.yoko.bindings.corba.Anonfixed;
+import org.apache.schemas.yoko.bindings.corba.Anonsequence;
+import org.apache.schemas.yoko.bindings.corba.Anonstring;
+import org.apache.schemas.yoko.bindings.corba.Array;
+import org.apache.schemas.yoko.bindings.corba.Const;
+import org.apache.schemas.yoko.bindings.corba.Enum;
+import org.apache.schemas.yoko.bindings.corba.Enumerator;
+import org.apache.schemas.yoko.bindings.corba.Exception;
+import org.apache.schemas.yoko.bindings.corba.Fixed;
+import org.apache.schemas.yoko.bindings.corba.MemberType;
+import org.apache.schemas.yoko.bindings.corba.Sequence;
+import org.apache.schemas.yoko.bindings.corba.Struct;
+import org.apache.schemas.yoko.bindings.corba.TypeMappingType;
+import org.apache.schemas.yoko.bindings.corba.Union;
+
+public class CorbaTypesExtensionHelper implements ExtensionDeserializer {
+
+ private static String corbaPrefix = "corba";
+ private static String corbaURI = "http://schemas.apache.org/yoko/bindings/corba";
+
+ public CorbaTypesExtensionHelper() {
+ }
+
+ public static void addExtension(ExtensionRegistry registry,
+ Class parentType,
+ String element) {
+ QName extQName = new QName(corbaURI, element, corbaPrefix);
+ CorbaTypesExtensionHelper helper = new CorbaTypesExtensionHelper();
+
+ registry.registerDeserializer(parentType, extQName, helper);
+ }
+
+ public ExtensibilityElement unmarshall(Class parentType, QName elementType,
+ Element el, Definition def,
+ ExtensionRegistry extReg)
+ throws WSDLException {
+ TypeMappingType mappingType = new TypeMappingType();
+
+ // Store the target namespace for the types
+ NamedNodeMap mappingAttributes = el.getAttributes();
+ for (int i = 0; i < mappingAttributes.getLength(); ++i) {
+ if (mappingAttributes.item(i).getNodeName().equals("targetNamespace")) {
+ mappingType.setTargetNamespace(mappingAttributes.item(i).getNodeValue());
+ }
+ }
+
+ // Get the types that are stored in this typemapping
+ NodeList typeChildNodes = el.getChildNodes();
+ for (int i = 0; i < typeChildNodes.getLength(); ++i) {
+ Node currentNode = typeChildNodes.item(i);
+
+ if (currentNode.getNodeName().equals("corba:const")) {
+ Const constType = getConstDefinition(currentNode);
+ mappingType.getStructOrExceptionOrUnion().add(constType);
+ } else if (currentNode.getNodeName().equals("corba:enum")) {
+ Enum enumType = getEnumDefinition(currentNode);
+ mappingType.getStructOrExceptionOrUnion().add(enumType);
+ } else if (currentNode.getNodeName().equals("corba:struct")) {
+ Struct structType = getStructDefinition(currentNode);
+ mappingType.getStructOrExceptionOrUnion().add(structType);
+ } else if (currentNode.getNodeName().equals("corba:exception")) {
+ Exception exceptType = getExceptionDefinition(currentNode);
+ mappingType.getStructOrExceptionOrUnion().add(exceptType);
+ } else if (currentNode.getNodeName().equals("corba:fixed")) {
+ Fixed fixedType = getFixedDefinition(currentNode);
+ mappingType.getStructOrExceptionOrUnion().add(fixedType);
+ } else if (currentNode.getNodeName().equals("corba:union")) {
+ Union unionType = getUnionDefinition(currentNode);
+ mappingType.getStructOrExceptionOrUnion().add(unionType);
+ } else if (currentNode.getNodeName().equals("corba:alias")) {
+ Alias aliasType = getAliasDefinition(currentNode);
+ mappingType.getStructOrExceptionOrUnion().add(aliasType);
+ } else if (currentNode.getNodeName().equals("corba:array")) {
+ Array arrayType = getArrayDefinition(currentNode);
+ mappingType.getStructOrExceptionOrUnion().add(arrayType);
+ } else if (currentNode.getNodeName().equals("corba:sequence")) {
+ Sequence sequenceType = getSequenceDefinition(currentNode);
+ mappingType.getStructOrExceptionOrUnion().add(sequenceType);
+ } else if (currentNode.getNodeName().equals("corba:anonstring")) {
+ Anonstring anonstringType = getAnonStringDefinition(currentNode);
+ mappingType.getStructOrExceptionOrUnion().add(anonstringType);
+ } else if (currentNode.getNodeName().equals("corba:anonfixed")) {
+ Anonfixed anonfixedType = getAnonFixedDefinition(currentNode);
+ mappingType.getStructOrExceptionOrUnion().add(anonfixedType);
+ } else if (currentNode.getNodeName().equals("corba:anonsequence")) {
+ Anonsequence anonsequenceType = getAnonSequenceDefinition(currentNode);
+ mappingType.getStructOrExceptionOrUnion().add(anonsequenceType);
+ } else if (currentNode.getNodeName().equals("corba:anonarray")) {
+ Anonarray anonarrayType = getAnonArrayDefinition(currentNode);
+ mappingType.getStructOrExceptionOrUnion().add(anonarrayType);
+ } else {
+ // TODO: How do we want to handle this?
+ }
+ }
+ return mappingType;
+ }
+
+ public Const getConstDefinition(Node node) {
+ Const constType = new Const();
+ NamedNodeMap constAttributes = node.getAttributes();
+
+ // Store information about the const
+ for (int i = 0; i < constAttributes.getLength(); ++i) {
+ if (constAttributes.item(i).getNodeName().equals("name")) {
+ constType.setName(constAttributes.item(i).getNodeValue());
+ } else if (constAttributes.item(i).getNodeName().equals("value")) {
+ constType.setValue(constAttributes.item(i).getNodeValue());
+ } else if (constAttributes.item(i).getNodeName().equals("idltype")) {
+ constType.setIdltype(QName.valueOf(constAttributes.item(i).getNodeValue()));
+ }
+ }
+ return constType;
+ }
+
+ public Enum getEnumDefinition(Node node) {
+ Enum enumType = new Enum();
+ NamedNodeMap enumAttributes = node.getAttributes();
+
+ // Store information about the enum
+ for (int i = 0; i < enumAttributes.getLength(); ++i) {
+ if (enumAttributes.item(i).getNodeName().equals("name")) {
+ enumType.setName(enumAttributes.item(i).getNodeValue());
+ } else if (enumAttributes.item(i).getNodeName().equals("repositoryID")) {
+ enumType.setRepositoryID(enumAttributes.item(i).getNodeValue());
+ }
+ }
+
+ // Store information about the enumerations
+ NodeList enumChildNodes = node.getChildNodes();
+ for (int i = 0; i < enumChildNodes.getLength(); ++i) {
+ Node currentNode = enumChildNodes.item(i);
+
+ if (currentNode.getNodeName().equals("corba:enumeration")) {
+ Enumerator enumerator = new Enumerator();
+ NamedNodeMap enumeratorAttrs = currentNode.getAttributes();
+
+ for (int j = 0; j < enumeratorAttrs.getLength(); ++j) {
+ Node enumeratorAttrNode = enumeratorAttrs.item(j);
+ if (enumeratorAttrNode.getNodeName().equals("value")) {
+ enumerator.setValue(enumeratorAttrNode.getNodeValue());
+ }
+ }
+ enumType.getEnumerator().add(enumerator);
+ }
+ }
+
+ return enumType;
+ }
+
+ public Struct getStructDefinition(Node node) {
+ Struct structType = new Struct();
+ NamedNodeMap structAttributes = node.getAttributes();
+
+ // Store information about the struct
+ for (int i = 0; i < structAttributes.getLength(); ++i) {
+ if (structAttributes.item(i).getNodeName().equals("name")) {
+ structType.setName(structAttributes.item(i).getNodeValue());
+ } else if (structAttributes.item(i).getNodeName().equals("repositoryID")) {
+ structType.setRepositoryID(structAttributes.item(i).getNodeValue());
+ }
+ }
+
+ // Store information about the structs members
+ NodeList structChildNodes = node.getChildNodes();
+ for (int i = 0; i < structChildNodes.getLength(); ++i) {
+ Node currentNode = structChildNodes.item(i);
+
+ if (currentNode.getNodeName().equals("corba:member")) {
+ MemberType member = new MemberType();
+ NamedNodeMap memberAttributes = currentNode.getAttributes();
+
+ for (int j = 0; j < memberAttributes.getLength(); ++j) {
+ Node memberAttrNode = memberAttributes.item(j);
+ if (memberAttrNode.getNodeName().equals("name")) {
+ member.setName(memberAttrNode.getNodeValue());
+ } else if (memberAttrNode.getNodeName().equals("idltype")) {
+ member.setIdltype(QName.valueOf(memberAttrNode.getNodeValue()));
+ }
+ }
+ structType.getMember().add(member);
+ }
+ }
+ return structType;
+ }
+
+ public Exception getExceptionDefinition(Node node) {
+ Exception exceptType = new Exception();
+ NamedNodeMap exceptAttributes = node.getAttributes();
+
+ // Store information about the exception
+ for (int i = 0; i < exceptAttributes.getLength(); ++i) {
+ if (exceptAttributes.item(i).getNodeName().equals("name")) {
+ exceptType.setName(exceptAttributes.item(i).getNodeValue());
+ } else if (exceptAttributes.item(i).getNodeName().equals("repositoryID")) {
+ exceptType.setRepositoryID(exceptAttributes.item(i).getNodeValue());
+ }
+ }
+
+ // Store information about the exceptions members
+ NodeList exceptChildNodes = node.getChildNodes();
+ for (int i = 0; i < exceptChildNodes.getLength(); ++i) {
+ Node currentNode = exceptChildNodes.item(i);
+
+ if (currentNode.getNodeName().equals("corba:member")) {
+ MemberType member = new MemberType();
+ NamedNodeMap memberAttributes = currentNode.getAttributes();
+
+ for (int j = 0; j < memberAttributes.getLength(); ++j) {
+ Node memberAttrNode = memberAttributes.item(j);
+ if (memberAttrNode.getNodeName().equals("name")) {
+ member.setName(memberAttrNode.getNodeValue());
+ } else if (memberAttrNode.getNodeName().equals("idltype")) {
+ member.setIdltype(QName.valueOf(memberAttrNode.getNodeValue()));
+ }
+ }
+ exceptType.getMember().add(member);
+ }
+ }
+ return exceptType;
+ }
+
+ public Fixed getFixedDefinition(Node node) {
+ Fixed fixedType = new Fixed();
+
+ // Store information about the fixed type
+ NamedNodeMap fixedAttributes = node.getAttributes();
+ for (int i = 0; i < fixedAttributes.getLength(); ++i) {
+ if (fixedAttributes.item(i).getNodeName().equals("name")) {
+ fixedType.setName(fixedAttributes.item(i).getNodeValue());
+ } else if (fixedAttributes.item(i).getNodeName().equals("repositoryID")) {
+ fixedType.setRepositoryID(fixedAttributes.item(i).getNodeValue());
+ } else if (fixedAttributes.item(i).getNodeName().equals("digits")) {
+ fixedType.setDigits(new Long(fixedAttributes.item(i).getNodeValue()));
+ } else if (fixedAttributes.item(i).getNodeName().equals("scale")) {
+ fixedType.setScale(new Long(fixedAttributes.item(i).getNodeValue()));
+ }
+ }
+ return fixedType;
+ }
+
+ public Union getUnionDefinition(Node node) {
+ System.out.println("DEBUG> - Union type defined");
+ return null;
+ }
+
+ public Alias getAliasDefinition(Node node) {
+ Alias aliasType = new Alias();
+
+ // Store information about the typedef
+ NamedNodeMap aliasAttributes = node.getAttributes();
+ for (int i = 0; i < aliasAttributes.getLength(); ++i) {
+ if (aliasAttributes.item(i).getNodeName().equals("name")) {
+ aliasType.setName(aliasAttributes.item(i).getNodeValue());
+ } else if (aliasAttributes.item(i).getNodeName().equals("repositoryID")) {
+ aliasType.setRepositoryID(aliasAttributes.item(i).getNodeValue());
+ } else if (aliasAttributes.item(i).getNodeName().equals("basetype")) {
+ aliasType.setBasetype(QName.valueOf(aliasAttributes.item(i).getNodeValue()));
+ }
+ }
+ return aliasType;
+ }
+
+ public Array getArrayDefinition(Node node) {
+ Array arrayType = new Array();
+
+ // Store information about the array
+ NamedNodeMap arrayAttributes = node.getAttributes();
+ for (int i = 0; i < arrayAttributes.getLength(); ++i) {
+ if (arrayAttributes.item(i).getNodeName().equals("name")) {
+ arrayType.setName(arrayAttributes.item(i).getNodeValue());
+ } else if (arrayAttributes.item(i).getNodeName().equals("repositoryID")) {
+ arrayType.setRepositoryID(arrayAttributes.item(i).getNodeValue());
+ } else if (arrayAttributes.item(i).getNodeName().equals("elemtype")) {
+ arrayType.setElemtype(QName.valueOf(arrayAttributes.item(i).getNodeValue()));
+ } else if (arrayAttributes.item(i).getNodeName().equals("bound")) {
+ arrayType.setBound(Long.parseLong(arrayAttributes.item(i).getNodeValue()));
+ }
+ }
+ return arrayType;
+ }
+
+ public Sequence getSequenceDefinition(Node node) {
+ Sequence sequenceType = new Sequence();
+
+ // Store information about the sequence
+ NamedNodeMap sequenceAttributes = node.getAttributes();
+ for (int i = 0; i < sequenceAttributes.getLength(); ++i) {
+ if (sequenceAttributes.item(i).getNodeName().equals("name")) {
+ sequenceType.setName(sequenceAttributes.item(i).getNodeValue());
+ } else if (sequenceAttributes.item(i).getNodeName().equals("repositoryID")) {
+ sequenceType.setRepositoryID(sequenceAttributes.item(i).getNodeValue());
+ } else if (sequenceAttributes.item(i).getNodeName().equals("elemType")) {
+ sequenceType.setElemtype(QName.valueOf(sequenceAttributes.item(i).getNodeValue()));
+ } else if (sequenceAttributes.item(i).getNodeName().equals("bound")) {
+ sequenceType.setBound(Long.parseLong(sequenceAttributes.item(i).getNodeValue()));
+ }
+ }
+ return sequenceType;
+ }
+
+ public Anonstring getAnonStringDefinition(Node node) {
+ return null;
+ }
+
+ public Anonfixed getAnonFixedDefinition(Node node) {
+ return null;
+ }
+
+ public Anonsequence getAnonSequenceDefinition(Node node) {
+ return null;
+ }
+
+ public Anonarray getAnonArrayDefinition(Node node) {
+ return null;
+ }
+}
\ No newline at end of file