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 [2/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/CorbaObjectHolder.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectHolder.java?rev=413964&view=auto
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectHolder.java (added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectHolder.java Tue Jun 13 12:40:51 2006
@@ -0,0 +1,206 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.schemas.yoko.bindings.corba.NamedType;
+
+import org.omg.CORBA.TCKind;
+import org.omg.CORBA.TypeCode;
+
+public class CorbaObjectHolder {
+
+ // object information
+ private final QName objectName;
+ private final QName idlType;
+ private final TypeCode typeCode;
+ private final NamedType typeDefinition;
+
+ // object data
+ private Object value;
+ private List<CorbaObjectHolder> members;
+
+ public CorbaObjectHolder(QName name, QName idl, TypeCode tc, Object typeDef) {
+ objectName = name;
+ idlType = idl;
+ typeCode = tc;
+ typeDefinition = (NamedType) typeDef;
+
+ value = null;
+ members = new ArrayList<CorbaObjectHolder>();
+ }
+
+ public boolean isPrimitiveType() {
+ return CorbaUtils.isPrimitiveIdlType(idlType);
+ }
+
+ public QName getName() {
+ return objectName;
+ }
+
+ public QName getIdlType() {
+ return idlType;
+ }
+
+ public NamedType getTypeDefintion() {
+ return typeDefinition;
+ }
+
+ public TypeCode getType() {
+ return typeCode;
+ }
+
+ public TCKind getTypeKind() {
+ return typeCode.kind();
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public String getValueData() {
+ String retValue = "";
+
+ switch (typeCode.kind().value()) {
+
+ case TCKind._tk_boolean:
+ retValue = ((Boolean) value).toString();
+ break;
+ case TCKind._tk_char:
+ char charValue = ((Character) value).charValue();
+ retValue = Byte.toString((byte) charValue);
+ break;
+ case TCKind._tk_wchar:
+ retValue = ((Character) value).toString();
+ break;
+ case TCKind._tk_octet:
+ retValue = ((Byte) value).toString();
+ break;
+ case TCKind._tk_short:
+ retValue = ((Short) value).toString();
+ break;
+ case TCKind._tk_long:
+ retValue = ((Long) value).toString();
+ break;
+ case TCKind._tk_ulong:
+ case TCKind._tk_longlong:
+ case TCKind._tk_ulonglong:
+ retValue = ((java.math.BigInteger) value).toString();
+ break;
+ case TCKind._tk_float:
+ retValue = ((Float) value).toString();
+ break;
+ case TCKind._tk_double:
+ retValue = ((Double) value).toString();
+ break;
+ case TCKind._tk_string:
+ case TCKind._tk_wstring:
+ retValue = (String)value;
+ break;
+ default:
+ // TODO: Revisit. Is this enough?
+ retValue = (String)value;
+ }
+
+ return retValue;
+ }
+
+ // TODO: UPDATE THIS SO THAT IT DOES NOT CLASH WITH THE STRING PARAMETER
+ // VERSION.
+ // This way we can directly store a value rather than converting to a string
+ // and
+ // then back to the value
+ // public void setValue(Object val) {
+ // value = val;
+ // }
+
+ // NOTE: we are using character data here because our objects will be read
+ // from a StAX XML Event,
+ // which gives us all data in character form.
+ // TODO: Need to add support for non-primitve values that do not have data
+ // members (e.g. fixed, enum, ...)
+ public void setValue(String data) {
+
+ switch (typeCode.kind().value()) {
+
+ case TCKind._tk_boolean:
+ value = new Boolean(data);
+ break;
+ case TCKind._tk_char:
+ // A char is mapped to a byte, we need it as a character
+ Byte byteValue = new Byte(data);
+ value = new Character((char) byteValue.byteValue());
+ break;
+ case TCKind._tk_wchar:
+ // A wide char is mapped to a string, we need it as a character
+ value = new Character(data.charAt(0));
+ break;
+ case TCKind._tk_octet:
+ // An octet is mapped to a short, we need it as a byte
+ Short shortValue = new Short(data);
+ value = new Byte(shortValue.byteValue());
+ break;
+ case TCKind._tk_short:
+ value = new Short(data);
+ break;
+ case TCKind._tk_long:
+ value = new Long(data);
+ break;
+ case TCKind._tk_ulong:
+ case TCKind._tk_longlong:
+ case TCKind._tk_ulonglong:
+ value = new java.math.BigInteger(data);
+ break;
+ case TCKind._tk_float:
+ value = new Float(data);
+ break;
+ case TCKind._tk_double:
+ value = new Double(data);
+ break;
+ case TCKind._tk_string:
+ case TCKind._tk_wstring:
+ value = data;
+ break;
+ default:
+ // TODO: Non-primitive. REVISIT: Is the string the best way to store
+ // this in an 'object'?
+ value = data;
+ }
+ }
+
+ public void addMember(CorbaObjectHolder el) {
+ members.add(el);
+ }
+
+ public CorbaObjectHolder getMember(int index) {
+ return members.get(index);
+ }
+
+ public List<CorbaObjectHolder> getMembers() {
+ return members;
+ }
+
+ public int getMembersSize() {
+ return members.size();
+ }
+}
Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReader.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReader.java?rev=413964&view=auto
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReader.java (added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReader.java Tue Jun 13 12:40:51 2006
@@ -0,0 +1,345 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import java.math.BigInteger;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.schemas.yoko.bindings.corba.Enum;
+import org.apache.schemas.yoko.bindings.corba.Enumerator;
+
+import org.objectweb.celtix.common.logging.LogUtils;
+
+import org.omg.CORBA.TCKind;
+import org.omg.CORBA.portable.InputStream;
+
+public class CorbaObjectReader {
+
+ private static final Logger LOG = LogUtils
+ .getL7dLogger(CorbaBindingImpl.class);
+
+ private InputStream stream;
+
+ public CorbaObjectReader(InputStream inStream) {
+ stream = inStream;
+ }
+
+ public void read(CorbaObjectHolder obj) throws CorbaBindingException {
+ // TODO: These will be updated so that we don't have to convert the
+ // value to a string.
+ switch (obj.getType().kind().value()) {
+ case TCKind._tk_boolean:
+ obj.setValue(this.readBoolean().toString());
+ break;
+ case TCKind._tk_char:
+ Character charValue = this.readChar();
+ byte charByteValue = (byte) charValue.charValue();
+ obj.setValue(Byte.toString(charByteValue));
+ break;
+ case TCKind._tk_wchar:
+ obj.setValue(this.readWChar().toString());
+ break;
+ case TCKind._tk_octet:
+ Byte octetValue = this.readOctet();
+ short octetShortValue = octetValue.shortValue();
+ obj.setValue(Short.toString(octetShortValue));
+ break;
+ case TCKind._tk_short:
+ obj.setValue(this.readShort().toString());
+ break;
+ case TCKind._tk_long:
+ obj.setValue(this.readLong().toString());
+ break;
+ case TCKind._tk_ulong:
+ obj.setValue(this.readULong().toString());
+ break;
+ case TCKind._tk_longlong:
+ obj.setValue(this.readLongLong().toString());
+ break;
+ case TCKind._tk_ulonglong:
+ obj.setValue(this.readULongLong().toString());
+ break;
+ case TCKind._tk_float:
+ obj.setValue(this.readFloat().toString());
+ break;
+ case TCKind._tk_double:
+ obj.setValue(this.readDouble().toString());
+ break;
+ case TCKind._tk_string:
+ obj.setValue(this.readString().toString());
+ break;
+ case TCKind._tk_wstring:
+ obj.setValue(this.readWString().toString());
+ break;
+
+ // Now for the complex types
+ case TCKind._tk_array:
+ this.readArray(obj);
+ break;
+ case TCKind._tk_sequence:
+ this.readSequence(obj);
+ break;
+ case TCKind._tk_struct:
+ this.readStruct(obj);
+ break;
+ case TCKind._tk_enum:
+ this.readEnum(obj);
+ break;
+ case TCKind._tk_except:
+ this.readException(obj);
+ break;
+ default:
+ // TODO: Provide Implementation. Do we throw an exception.
+ }
+ }
+
+ // -- primitive types --
+ public Boolean readBoolean() throws CorbaBindingException {
+ try {
+ Boolean result;
+ result = new Boolean(stream.read_boolean());
+ return result;
+ } catch (org.omg.CORBA.MARSHAL ex) {
+ LOG.log(Level.SEVERE, "CorbaObjectReader: could not read boolean");
+ throw new CorbaBindingException("CorbaObjectReader: readBoolean MARSHAL exception", ex);
+ }
+ }
+
+ public Character readChar() throws CorbaBindingException {
+ try {
+ Character result;
+ result = new Character(stream.read_char());
+ return result;
+ } catch (org.omg.CORBA.MARSHAL ex) {
+ LOG.log(Level.SEVERE, "CorbaObjectReader: could not read character");
+ throw new CorbaBindingException("CorbaObjectReader: readChar MARSHAL exception", ex);
+ }
+ }
+
+ public Character readWChar() throws CorbaBindingException {
+ try {
+ Character result;
+ result = new Character(stream.read_wchar());
+ return result;
+ } catch (org.omg.CORBA.MARSHAL ex) {
+ LOG.log(Level.SEVERE, "CorbaObjectReader: could not read wide character");
+ throw new CorbaBindingException("CorbaObjectReader: readWChar MARSHAL exception", ex);
+ }
+ }
+
+ public Byte readOctet() throws CorbaBindingException {
+ try {
+ Byte result;
+ result = new Byte(stream.read_octet());
+ return result;
+ } catch (org.omg.CORBA.MARSHAL ex) {
+ LOG.log(Level.SEVERE, "CorbaObjectReader: could not read octet");
+ throw new CorbaBindingException("CorbaObjectReader: readOctet MARSHAL exception", ex);
+ }
+ }
+
+ public Short readShort() throws CorbaBindingException {
+ try {
+ Short result;
+ result = new Short(stream.read_short());
+ return result;
+ } catch (org.omg.CORBA.MARSHAL ex) {
+ LOG.log(Level.SEVERE, "CorbaObjectReader: could not read short");
+ throw new CorbaBindingException("CorbaObjectReader: readShort MARSHAL exception", ex);
+ }
+ }
+
+ public Long readLong() throws CorbaBindingException {
+ try {
+ Long result;
+ result = new Long(stream.read_long());
+ return result;
+ } catch (org.omg.CORBA.MARSHAL ex) {
+ LOG.log(Level.SEVERE, "CorbaObjectReader: could not read long");
+ throw new CorbaBindingException("CorbaObjectReader: readLong MARSHAL exception", ex);
+ }
+ }
+
+ public BigInteger readULong() throws CorbaBindingException {
+ try {
+ java.math.BigInteger result;
+ result = new BigInteger(stream.read_ulong() + "");
+ return result;
+ } catch (org.omg.CORBA.MARSHAL ex) {
+ LOG.log(Level.SEVERE, "CorbaObjectReader: could not read unsigned long");
+ throw new CorbaBindingException("CorbaObjectReader: readULong MARSHAL exception", ex);
+ }
+ }
+
+ public BigInteger readLongLong() throws CorbaBindingException {
+ try {
+ BigInteger result;
+ result = new BigInteger(stream.read_longlong() + "");
+ return result;
+ } catch (org.omg.CORBA.MARSHAL ex) {
+ LOG.log(Level.SEVERE, "CorbaObjectReader: could not read long long");
+ throw new CorbaBindingException("CorbaObjectReader: readLongLong MARSHAL exception", ex);
+ }
+ }
+
+ public BigInteger readULongLong() throws CorbaBindingException {
+ try {
+ BigInteger result;
+ result = new BigInteger(stream.read_ulonglong() + "");
+ return result;
+ } catch (org.omg.CORBA.MARSHAL ex) {
+ LOG.log(Level.SEVERE, "CorbaObjectReader: could not read unsigned long long");
+ throw new CorbaBindingException("CorbaObjectReader: readULongLong MARSHAL exception", ex);
+ }
+ }
+
+ public Float readFloat() throws CorbaBindingException {
+ try {
+ Float result;
+ result = new Float(stream.read_float());
+ return result;
+ } catch (org.omg.CORBA.MARSHAL ex) {
+ LOG.log(Level.SEVERE, "CorbaObjectReader: could not read float");
+ throw new CorbaBindingException("CorbaObjectReader: readFloat MARSHAL exception", ex);
+ }
+ }
+
+ public Double readDouble() throws CorbaBindingException {
+ try {
+ Double result;
+ result = new Double(stream.read_double());
+ return result;
+ } catch (org.omg.CORBA.MARSHAL ex) {
+ LOG.log(Level.SEVERE, "CorbaObjectReader: could not read double");
+ throw new CorbaBindingException("CorbaObjectReader: readDouble MARSHAL exception", ex);
+ }
+ }
+
+ public String readString() throws CorbaBindingException {
+ try {
+ String result;
+ result = stream.read_string();
+ return result;
+ } catch (org.omg.CORBA.MARSHAL ex) {
+ LOG.log(Level.SEVERE, "CorbaObjectReader: could not read string");
+ throw new CorbaBindingException("CorbaObjectReader: readString MARSHAL exception", ex);
+ }
+ }
+
+ public String readWString() throws CorbaBindingException {
+ try {
+ String result;
+ result = stream.read_wstring();
+ return result;
+ } catch (org.omg.CORBA.MARSHAL ex) {
+ LOG.log(Level.SEVERE, "CorbaObjectReader: could not read wide string");
+ throw new CorbaBindingException("CorbaObjectReader: readWString MARSHAL exception", ex);
+ }
+ }
+
+ public void readAny(CorbaObjectHolder obj) throws CorbaBindingException {
+ // TODO: provide implementation
+ throw new CorbaBindingException("CorbaObjectReader: readAny not yet implemented");
+ }
+
+ // -- complex types --
+ public void readConstant(CorbaObjectHolder obj) throws CorbaBindingException {
+ // TODO: provide implementation - does this one make sense for the
+ // binding
+ throw new CorbaBindingException("CorbaObjectReader: readConstant not yet implemented");
+ }
+
+ public void readEnum(CorbaObjectHolder obj) throws CorbaBindingException {
+ int enumIndex = stream.read_long();
+
+ Enum enumType = (Enum) obj.getTypeDefintion();
+ List<Enumerator> enumerators = enumType.getEnumerator();
+
+ obj.setValue(enumerators.get(enumIndex).getValue());
+ }
+
+ public String readEnumLabel() throws CorbaBindingException {
+ // TODO: provide implementation
+ throw new CorbaBindingException("CorbaObjectReader: readEnumLabel not yet implemented");
+ }
+
+ public void readStruct(CorbaObjectHolder obj) throws CorbaBindingException {
+ List<CorbaObjectHolder> structMembers = obj.getMembers();
+
+ for (int i = 0; i < structMembers.size(); ++i) {
+ this.read(structMembers.get(i));
+ }
+ }
+
+ public void readException(CorbaObjectHolder obj) throws CorbaBindingException {
+ // Exceptions are very similar to a struct, except that they also have a repository ID which gets
+ // propgated as a string. This will be stored in the object holders value field
+ List<CorbaObjectHolder> exceptElements = obj.getMembers();
+
+ String exceptId = stream.read_string();
+ obj.setValue(exceptId);
+
+ for (int i = 0; i < exceptElements.size(); ++i) {
+ this.read(exceptElements.get(i));
+ }
+ }
+
+ public void readFixed(CorbaObjectHolder obj) throws CorbaBindingException {
+ // TODO: provide implementation
+ throw new CorbaBindingException("CorbaObjectReader: readFixed not yet implemented");
+ }
+
+ public void readUnion(CorbaObjectHolder obj) throws CorbaBindingException {
+ // TODO: provide implementation
+ throw new CorbaBindingException("CorbaObjectReader: readUnion not yet implemented");
+ }
+
+ public void readTypeDef(CorbaObjectHolder obj) throws CorbaBindingException {
+ // TODO: provide implementation - does this one make sense for the
+ // binding
+ throw new CorbaBindingException("CorbaObjectReader: readTypeDef not yet implemented");
+ }
+
+ public void readArray(CorbaObjectHolder obj) throws CorbaBindingException {
+ List<CorbaObjectHolder> arrayElements = obj.getMembers();
+
+ for (int i = 0; i < arrayElements.size(); ++i) {
+ this.read(arrayElements.get(i));
+ }
+ }
+
+ public void readSequence(CorbaObjectHolder obj)
+ throws CorbaBindingException {
+ List<CorbaObjectHolder> seqElements = obj.getMembers();
+
+ int length = stream.read_ulong();
+ assert length == seqElements.size();
+
+ for (int i = 0; i < length; ++i) {
+ this.read(seqElements.get(i));
+ }
+ }
+
+ public boolean isEnum() {
+ // TODO: Provide complete implementation
+ return false;
+ }
+}
Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectWriter.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectWriter.java?rev=413964&view=auto
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectWriter.java (added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectWriter.java Tue Jun 13 12:40:51 2006
@@ -0,0 +1,232 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import java.math.BigInteger;
+import java.util.List;
+
+import org.omg.CORBA.Any;
+import org.omg.CORBA.TCKind;
+import org.omg.CORBA.portable.OutputStream;
+
+public class CorbaObjectWriter {
+
+ private OutputStream stream;
+
+ public CorbaObjectWriter(OutputStream outStream) {
+ stream = outStream;
+ }
+
+ public void write(CorbaObjectHolder obj) {
+ assert obj != null;
+
+ switch (obj.getType().kind().value()) {
+ case TCKind._tk_boolean:
+ this.writeBoolean((Boolean) obj.getValue());
+ break;
+ case TCKind._tk_char:
+ this.writeChar((Character) obj.getValue());
+ break;
+ case TCKind._tk_wchar:
+ this.writeWChar((Character) obj.getValue());
+ break;
+ case TCKind._tk_octet:
+ this.writeOctet((Byte) obj.getValue());
+ break;
+ case TCKind._tk_short:
+ this.writeShort((Short) obj.getValue());
+ break;
+ case TCKind._tk_long:
+ this.writeLong((Long) obj.getValue());
+ break;
+ case TCKind._tk_ulong:
+ this.writeULong((BigInteger) obj.getValue());
+ break;
+ case TCKind._tk_longlong:
+ this.writeLongLong((BigInteger) obj.getValue());
+ break;
+ case TCKind._tk_ulonglong:
+ this.writeULongLong((BigInteger) obj.getValue());
+ break;
+ case TCKind._tk_float:
+ this.writeFloat((Float) obj.getValue());
+ break;
+ case TCKind._tk_double:
+ this.writeDouble((Double) obj.getValue());
+ break;
+ case TCKind._tk_string:
+ this.writeString((String) obj.getValue());
+ break;
+ case TCKind._tk_wstring:
+ this.writeWString((String) obj.getValue());
+ break;
+
+ // Now for the complex types
+ case TCKind._tk_array:
+ this.writeArray(obj);
+ break;
+ case TCKind._tk_sequence:
+ this.writeSequence(obj);
+ break;
+ case TCKind._tk_struct:
+ this.writeStruct(obj);
+ break;
+ case TCKind._tk_enum:
+ this.writeEnum(obj);
+ break;
+ case TCKind._tk_except:
+ this.writeException(obj);
+ break;
+ default:
+ // TODO: Provide Implementation. Do we throw an exception.
+ }
+ }
+
+ // -- primitive types --
+ public void writeBoolean(Boolean b) throws CorbaBindingException {
+ stream.write_boolean(b.booleanValue());
+ }
+
+ public void writeChar(Character c) throws CorbaBindingException {
+ stream.write_char(c.charValue());
+ }
+
+ public void writeWChar(Character c) throws CorbaBindingException {
+ stream.write_wchar(c.charValue());
+ }
+
+ public void writeOctet(Byte b) throws CorbaBindingException {
+ stream.write_octet(b.byteValue());
+ }
+
+ public void writeShort(Short s) throws CorbaBindingException {
+ stream.write_short(s.shortValue());
+ }
+
+ public void writeLong(Long l) throws CorbaBindingException {
+ stream.write_long((int) l.longValue());
+ }
+
+ public void writeULong(java.math.BigInteger l) throws CorbaBindingException {
+ stream.write_ulong((int) l.longValue());
+ }
+
+ public void writeLongLong(java.math.BigInteger l) throws CorbaBindingException {
+ stream.write_longlong(l.longValue());
+ }
+
+ public void writeULongLong(java.math.BigInteger l) throws CorbaBindingException {
+ stream.write_ulonglong(l.longValue());
+ }
+
+ public void writeFloat(Float f) throws CorbaBindingException {
+ stream.write_float(f.floatValue());
+ }
+
+ public void writeDouble(Double d) throws CorbaBindingException {
+ stream.write_double(d.doubleValue());
+ }
+
+ public void writeString(String s) throws CorbaBindingException {
+ stream.write_string(s);
+ }
+
+ public void writeWString(String s) throws CorbaBindingException {
+ stream.write_wstring(s);
+ }
+
+ public void writeAny(Any a) throws CorbaBindingException {
+ // TODO: provide implementation
+ throw new CorbaBindingException("CorbaObjectWriter: writeAny not yet implemented");
+ }
+
+ // -- complex types --
+ public void writeConstant(CorbaObjectHolder type) throws CorbaBindingException {
+ // TODO: provide implementation - does this one make sense for the
+ // binding
+ throw new CorbaBindingException("CorbaObjectWriter: writeConstant not yet implemented");
+ }
+
+ public void writeEnum(CorbaObjectHolder type) throws CorbaBindingException {
+ // TODO: provide implementation
+ throw new CorbaBindingException("CorbaObjectWriter: writeEnum not yet implemented");
+ }
+
+ public void writeEnumLabel(String label) throws CorbaBindingException {
+ // TODO: provide implementation
+ throw new CorbaBindingException("CorbaObjectWriter: writeEnumLabel not yet implemented");
+ }
+
+ public void writeStruct(CorbaObjectHolder obj) throws CorbaBindingException {
+ List<CorbaObjectHolder> structElements = obj.getMembers();
+
+ for (int i = 0; i < structElements.size(); ++i) {
+ this.write(structElements.get(i));
+ }
+ }
+
+ public void writeException(CorbaObjectHolder type) throws CorbaBindingException {
+ // TODO: provide implementation
+ throw new CorbaBindingException("CorbaObjectWriter: writeException not yet implemented");
+ }
+
+ public void writeFixed(CorbaObjectHolder type) throws CorbaBindingException {
+ // TODO: provide implementation
+ throw new CorbaBindingException("CorbaObjectWriter: writeFixed not yet implemented");
+ }
+
+ public void writeUnion(CorbaObjectHolder type) throws CorbaBindingException {
+ // TODO: provide implementation
+ throw new CorbaBindingException("CorbaObjectWriter: writeUnion not yet implemented");
+ }
+
+ public void writeTypeDef(CorbaObjectHolder type) throws CorbaBindingException {
+ // TODO: provide implementation
+ throw new CorbaBindingException("CorbaObjectWriter: writeTypeDef not yet implemented");
+ }
+
+ public void writeArray(CorbaObjectHolder obj) throws CorbaBindingException {
+ List<CorbaObjectHolder> arrayElements = obj.getMembers();
+
+ for (int i = 0; i < arrayElements.size(); ++i) {
+ this.write(arrayElements.get(i));
+ }
+ }
+
+ public void writeSequence(CorbaObjectHolder obj) throws CorbaBindingException {
+ List<CorbaObjectHolder> seqElements = obj.getMembers();
+ int length = seqElements.size();
+
+ stream.write_ulong(length);
+
+ for (int i = 0; i < length; ++i) {
+ this.write(seqElements.get(i));
+ }
+ }
+
+ public void writeObject(CorbaObjectHolder type) throws CorbaBindingException {
+ // TODO: provide implementation
+ throw new CorbaBindingException("CorbaObjectWriter: writeObject not yet implemented");
+ }
+
+ public boolean isEnum() {
+ // TODO: Provide complete implementation
+ return false;
+ }
+}
\ No newline at end of file
Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaServerBinding.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaServerBinding.java?rev=413964&r1=413963&r2=413964&view=diff
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaServerBinding.java (original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaServerBinding.java Tue Jun 13 12:40:51 2006
@@ -1,47 +1,138 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
-import java.lang.reflect.Method;
-import java.util.List;
-//import java.util.logging.Level;
-//import java.util.logging.Logger;
+import java.io.IOException;
-import javax.xml.ws.handler.MessageContext;
+import javax.wsdl.WSDLException;
+
+import org.apache.schemas.yoko.bindings.corba.AddressType;
import org.objectweb.celtix.Bus;
+import org.objectweb.celtix.bindings.AbstractBindingBase;
import org.objectweb.celtix.bindings.AbstractBindingImpl;
-import org.objectweb.celtix.bindings.AbstractServerBinding;
+import org.objectweb.celtix.bindings.DataBindingCallback;
+import org.objectweb.celtix.bindings.ServerBinding;
import org.objectweb.celtix.bindings.ServerBindingEndpointCallback;
-//import org.objectweb.celtix.common.logging.LogUtils;
+import org.objectweb.celtix.context.OutputStreamMessageContext;
import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
-public class CorbaServerBinding extends AbstractServerBinding {
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.Policy;
+import org.omg.PortableServer.POA;
+import org.omg.PortableServer.POAHelper;
+import org.omg.PortableServer.POAManager;
+
+public class CorbaServerBinding extends AbstractBindingBase implements ServerBinding {
-// private static final Logger LOG = LogUtils.getL7dLogger(CorbaServerBinding.class);
protected final CorbaBindingImpl corbaBinding;
-
- public CorbaServerBinding(Bus b,
- EndpointReferenceType ref,
- ServerBindingEndpointCallback cbFactory) {
- super(b, ref, cbFactory);
- corbaBinding = new CorbaBindingImpl(b, ref, true);
+ protected ServerBindingEndpointCallback sbeCallback;
+ private ORB orb;
+
+ public CorbaServerBinding(Bus b, EndpointReferenceType ref, ServerBindingEndpointCallback cbFactory) {
+ super(b, ref);
+
+ sbeCallback = cbFactory;
+
+ // TODO: Get any configuration options for the ORB and set the appropriate properties.
+ java.util.Properties props = System.getProperties();
+ props.put("org.omg.CORBA.ORBClass", "org.apache.yoko.orb.CORBA.ORB");
+ props.put("org.omg.CORBA.ORBSingletonClass", "org.apache.yoko.orb.CORBA.ORBSingleton");
+ props.put("yoko.orb.id", "Yoko-Server-Binding");
+ orb = ORB.init(new String[0], props);
+
+ corbaBinding = new CorbaBindingImpl(b, ref, orb, true);
}
-
+
+ // -- from BindingBase interface --
public AbstractBindingImpl getBindingImpl() {
return corbaBinding;
}
- protected Method getSEIMethod(List<Class<?>> classList, MessageContext ctx) {
- // TODO - provide implementation
- return null;
- }
-
public boolean isBindingCompatible(String address) {
// TODO - add support for files which contain IORs
- return address.startsWith("IOR:") || address.startsWith("corbaloc:");
+ return address.startsWith("IOR:")
+ || address.startsWith("corbaloc:")
+ || address.startsWith("relfile");
+ }
+
+ // -- from ServerBinding interface --
+ public void activate() throws WSDLException, IOException {
+ // Get the address that the DSI servant should be publishing
+
+ String location = "";
+ AddressType address = CorbaUtils.getCorbaAddressType(corbaBinding.getBus(),
+ corbaBinding.getEndpointReference());
+ if (address != null) {
+ location = address.getLocation();
+ }
+
+ org.omg.CORBA.Object obj = null;
+ try {
+ POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
+ POAManager poaManager = rootPOA.the_POAManager();
+
+ Policy[] policies = new Policy[3];
+ policies[0] = rootPOA
+ .create_lifespan_policy(
+ org.omg.PortableServer.LifespanPolicyValue.PERSISTENT);
+ policies[1] = rootPOA
+ .create_implicit_activation_policy(
+ org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION);
+ policies[2] = rootPOA
+ .create_id_uniqueness_policy(
+ org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID);
+
+ POA bindingPOA = rootPOA.create_POA("BindingPOA", poaManager, policies);
+ CorbaDSIServant servant = new CorbaDSIServant(orb, bindingPOA, this, sbeCallback);
+ byte[] objectId = bindingPOA.activate_object(servant);
+ obj = bindingPOA.id_to_reference(objectId);
+
+ // TODO: Revisit. For now, we are testing with the relfile:/ identifier. Make this
+ // more generic.
+ if (location.startsWith("relfile:/")) {
+ String iorFile = location.substring("relfile:/".length(), location.length());
+ CorbaUtils.exportObjectReferenceToFile(obj, orb, iorFile);
+ } else {
+ // TODO: Provide other export mechanisms
+ }
+
+ poaManager.activate();
+ } catch (Exception ex) {
+ // TODO: Throw appropriate exception
+ throw new CorbaBindingException("Unable to active CORBA servant", ex);
+ }
+ }
+
+ public void deactivate() throws IOException {
+ if (orb != null) {
+ try {
+ orb.destroy();
+ } catch (Exception ex) {
+ // TODO: For now, we just consume. Revisit.
+ }
+ }
}
- public javax.xml.namespace.QName getOperationName(MessageContext ctx) {
- // TODO - provide implementation
- return null;
+ public void partialResponse(OutputStreamMessageContext outputContext,
+ DataBindingCallback callback)
+ throws IOException {
+ // Complete? No concept of a partial response in CORBA
}
}
Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStreamable.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStreamable.java?rev=413964&view=auto
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStreamable.java (added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStreamable.java Tue Jun 13 12:40:51 2006
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import javax.xml.namespace.QName;
+
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+import org.omg.CORBA.portable.Streamable;
+
+public class CorbaStreamable implements Streamable {
+
+ private CorbaObjectHolder value;
+ private QName name;
+ private int mode;
+ private TypeCode typecode;
+
+ public CorbaStreamable(CorbaObjectHolder obj, QName elName) {
+ value = obj;
+ name = elName;
+ typecode = obj.getType();
+
+ mode = org.omg.CORBA.ARG_OUT.value;
+ }
+
+ public void _read(InputStream istream) {
+ try {
+ CorbaObjectReader reader = new CorbaObjectReader(istream);
+ reader.read(value);
+ } catch (java.lang.Exception ex) {
+ throw new CorbaBindingException("Error reading streamable value", ex);
+ }
+ }
+
+ public void _write(OutputStream ostream) {
+ try {
+ CorbaObjectWriter writer = new CorbaObjectWriter(ostream);
+ writer.write(value);
+ } catch (java.lang.Exception ex) {
+ throw new CorbaBindingException("Error writing streamable value", ex);
+ }
+ }
+
+ public TypeCode _type() {
+ return typecode;
+ }
+
+ public CorbaObjectHolder getObject() {
+ return value;
+ }
+
+ public void setObject(CorbaObjectHolder obj) {
+ // TODO: This will need to handle more complex situations. For now,
+ // this is just its basic implementation
+ if (obj == null) {
+ // TODO: throw an exception
+ }
+ value = obj;
+ }
+
+ public int getMode() {
+ return mode;
+ }
+
+ public void setMode(int md) {
+ mode = md;
+ }
+
+ public String getName() {
+ return name.getLocalPart();
+ }
+}
\ No newline at end of file
Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaTypeMap.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaTypeMap.java?rev=413964&view=auto
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaTypeMap.java (added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaTypeMap.java Tue Jun 13 12:40:51 2006
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.schemas.yoko.bindings.corba.CorbaType;
+
+public class CorbaTypeMap {
+
+ private String targetNamespace;
+
+ private String prefix;
+
+ private Map<String, CorbaType> typeMap;
+
+ public CorbaTypeMap(String namespace) {
+ targetNamespace = namespace;
+ typeMap = new HashMap<String, CorbaType>();
+ }
+
+ public void addType(String name, CorbaType type) {
+ typeMap.put(name, type);
+ }
+
+ public CorbaType getType(String name) {
+ assert name != null;
+
+ return typeMap.get(name);
+ }
+
+ public String getTargetNamespace() {
+ return targetNamespace;
+ }
+
+ public void setPrefix(String pfx) {
+ prefix = pfx;
+ }
+
+ public String getPrefix() {
+ return prefix;
+ }
+}
Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java?rev=413964&view=auto
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java (added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java Tue Jun 13 12:40:51 2006
@@ -0,0 +1,400 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.Port;
+import javax.xml.namespace.QName;
+
+import org.apache.schemas.yoko.bindings.corba.AddressType;
+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.Anonwstring;
+import org.apache.schemas.yoko.bindings.corba.Array;
+import org.apache.schemas.yoko.bindings.corba.BindingType;
+import org.apache.schemas.yoko.bindings.corba.Const;
+import org.apache.schemas.yoko.bindings.corba.CorbaType;
+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.NamedType;
+import org.apache.schemas.yoko.bindings.corba.OperationType;
+import org.apache.schemas.yoko.bindings.corba.Sequence;
+import org.apache.schemas.yoko.bindings.corba.Struct;
+import org.apache.schemas.yoko.bindings.corba.Union;
+
+import org.objectweb.celtix.Bus;
+import org.objectweb.celtix.helpers.WSDLHelper;
+import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
+import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
+
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.StructMember;
+import org.omg.CORBA.TCKind;
+import org.omg.CORBA.TypeCode;
+
+public class CorbaUtils {
+
+ static Map<QName, TCKind> PRIMITIVE_TYPECODES = new HashMap<QName, TCKind>();
+
+ public static TypeCode getTypeCode(ORB orb, QName type, List<CorbaTypeMap> typeMaps) {
+ TypeCode tc = null;
+
+ // first see if it is a primitive
+ tc = getPrimitiveTypeCode(orb, type);
+ if (tc == null) {
+ // this means it is not a primitive type
+ CorbaTypeMap currentMap = null;
+ for (int i = 0; i < typeMaps.size(); ++i) {
+ if (typeMaps.get(i).getPrefix().equals(type.getPrefix())) {
+ currentMap = typeMaps.get(i);
+ break;
+ }
+ }
+
+ if (currentMap == null) {
+ throw new CorbaBindingException("Unable to locate typemap for prefix " + type.getPrefix());
+ }
+
+ CorbaType obj = currentMap.getType(type.getLocalPart());
+ if (obj == null) {
+ throw new CorbaBindingException("Unable to locate object definition");
+ }
+
+ tc = getComplexTypeCode(orb, type, obj, typeMaps);
+ }
+ return tc;
+ }
+
+ public static TypeCode getPrimitiveTypeCode(ORB orb, QName type) {
+ TCKind kind = PRIMITIVE_TYPECODES.get(type);
+ if (kind != null) {
+ return orb.get_primitive_tc(kind);
+ }
+
+ // There is a possiblitity that the idl type will not have its namespace
+ // URI set if it has
+ // been read directly from the WSDL file as a string. Try with the
+ // standard corba namespace URI.
+ if (type.getNamespaceURI() == null) {
+ QName uriIdltype = new QName(CorbaConstants.NU_WSDL_CORBA, type.getLocalPart(), type.getPrefix());
+
+ kind = PRIMITIVE_TYPECODES.get(uriIdltype);
+ if (kind != null) {
+ return orb.get_primitive_tc(kind);
+ }
+ }
+ return null;
+ }
+
+ public static TypeCode getComplexTypeCode(ORB orb, QName type, Object obj, List<CorbaTypeMap> typeMaps) {
+
+ TypeCode tc = null;
+
+ if (obj instanceof Alias) {
+ Alias aliasType = (Alias) obj;
+ tc = getTypeCode(orb, aliasType.getBasetype(), typeMaps);
+ } else if (obj instanceof Anonarray) {
+ // TODO: Implement
+ // Should be similar to an array
+ } else if (obj instanceof Anonfixed) {
+ // TODO: Implement
+ // Should be similar to a fixed
+ } else if (obj instanceof Anonsequence) {
+ // TODO: Implement
+ // Should be similar to a sequence
+ } else if (obj instanceof Anonstring) {
+ // TODO: Implement
+ // Should be similar to a string
+ } else if (obj instanceof Anonwstring) {
+ // TODO: Implement
+ // Should be similar to a wstring
+ } else if (obj instanceof Array) {
+ Array arrayType = (Array) obj;
+ tc = orb.create_array_tc((int) arrayType.getBound(),
+ getTypeCode(orb, arrayType.getElemtype(), typeMaps));
+ } else if (obj instanceof Const) {
+ Const constType = (Const) obj;
+ tc = getTypeCode(orb, constType.getIdltype(), typeMaps);
+ } else if (obj instanceof Enum) {
+ Enum enumType = (Enum) obj;
+ String name = enumType.getName();
+ List enums = enumType.getEnumerator();
+ String[] members = new String[enums.size()];
+
+ for (int i = 0; i < members.length; ++i) {
+ members[i] = ((Enumerator) enums.get(i)).getValue();
+ }
+ tc = orb.create_enum_tc(enumType.getRepositoryID(), name, members);
+ } else if (obj instanceof Exception) {
+ Exception exceptType = (Exception) obj;
+
+ // TODO: check to see if this is a recursive type.
+ List list = exceptType.getMember();
+ StructMember[] members = new StructMember[list.size()];
+ for (int i = 0; i < members.length; ++i) {
+ MemberType member = (MemberType) list.get(i);
+ members[i] = new StructMember(member.getName(),
+ getTypeCode(orb, member.getIdltype(), typeMaps), null);
+ }
+ String name = exceptType.getName();
+ tc = orb.create_exception_tc(exceptType.getRepositoryID(), name, members);
+ } else if (obj instanceof Fixed) {
+ Fixed fixedType = (Fixed) obj;
+ tc = orb.create_fixed_tc((short) fixedType.getDigits(), (short) fixedType.getScale());
+ } else if (obj instanceof Sequence) {
+ Sequence seqType = (Sequence) obj;
+ tc = orb.create_sequence_tc((int) seqType.getBound(),
+ getTypeCode(orb, seqType.getElemtype(), typeMaps));
+ } else if (obj instanceof Struct) {
+ Struct structType = (Struct) obj;
+
+ // TODO: check to see if this is a recursive type.
+ List list = structType.getMember();
+ StructMember[] members = new StructMember[list.size()];
+ for (int i = 0; i < members.length; ++i) {
+ MemberType member = (MemberType) list.get(i);
+ members[i] = new StructMember(member.getName(),
+ getTypeCode(orb, member.getIdltype(), typeMaps), null);
+ }
+ String name = structType.getName();
+ tc = orb.create_exception_tc(structType.getRepositoryID(), name, members);
+ } else if (obj instanceof Union) {
+ // TODO: Implement
+ }
+ return tc;
+ }
+
+ public static boolean isPrimitiveIdlType(QName idltype) {
+ TCKind kind = PRIMITIVE_TYPECODES.get(idltype);
+ if (kind != null) {
+ return true;
+ }
+
+ // There is a possiblitity that the idl type will not have its namespace
+ // URI set if it has
+ // been read directly from the WSDL file as a string. Try with the
+ // standard corba namespace URI.
+ if (idltype.getNamespaceURI() == null) {
+ QName uriIdltype = new QName(CorbaConstants.NU_WSDL_CORBA, idltype.getLocalPart(),
+ idltype.getPrefix());
+ kind = PRIMITIVE_TYPECODES.get(uriIdltype);
+ if (kind != null) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static QName getMemberIdlType(NamedType obj, QName name) {
+ // NOTE: Does this really only apply to structs, exceptions, and unions?
+
+ if (obj instanceof Struct) {
+ Struct structType = (Struct) obj;
+ List<MemberType> members = structType.getMember();
+ for (int i = 0; i < members.size(); ++i) {
+ MemberType m = members.get(i);
+ if (m.getName().equals(name)) {
+ return m.getIdltype();
+ }
+ }
+ } else if (obj instanceof Exception) {
+ Exception exceptType = (Exception) obj;
+ List<MemberType> members = exceptType.getMember();
+ for (int i = 0; i < members.size(); ++i) {
+ MemberType m = members.get(i);
+ if (m.getName().equals(name)) {
+ return m.getIdltype();
+ }
+ }
+ } else if (obj instanceof Union) {
+ // TODO
+ } else if (obj instanceof Sequence) {
+ // TODO
+ } else if (obj instanceof Array) {
+ // TODO
+ }
+ return null;
+ }
+
+ public static NamedType getCorbaType(QName idlType, List<CorbaTypeMap> typeMaps) {
+ CorbaTypeMap currentMap = null;
+ for (int i = 0; i < typeMaps.size(); ++i) {
+ currentMap = typeMaps.get(i);
+ if (currentMap.getPrefix().equals(idlType.getPrefix())) {
+ // elements in the typemap should also be NamedTypes
+ return (NamedType) currentMap.getType(idlType.getLocalPart());
+ }
+ }
+
+ return null;
+ }
+
+ public static NamedType getMemberCorbaType(NamedType obj, QName name, List<CorbaTypeMap> typeMaps) {
+ NamedType type = null;
+
+ if (obj instanceof Struct) {
+ Struct structType = (Struct) obj;
+ List<MemberType> members = structType.getMember();
+ QName memberType = null;
+ for (int i = 0; i < members.size(); ++i) {
+ if (members.get(i).getName().equals(name)) {
+ memberType = members.get(i).getIdltype();
+ break;
+ }
+ }
+
+ if (!isPrimitiveIdlType(memberType) && memberType != null) {
+ for (int i = 0; i < typeMaps.size(); ++i) {
+ if (typeMaps.get(i).getPrefix().equals(memberType.getPrefix())) {
+ type = (NamedType) typeMaps.get(i).getType(memberType.getLocalPart());
+ break;
+ }
+ }
+ }
+ } else if (obj instanceof Exception) {
+ Exception exceptType = (Exception) obj;
+ List<MemberType> members = exceptType.getMember();
+ QName memberType = null;
+ for (int i = 0; i < members.size(); ++i) {
+ if (members.get(i).getName().equals(name)) {
+ memberType = members.get(i).getIdltype();
+ break;
+ }
+ }
+
+ if (!isPrimitiveIdlType(memberType) && memberType != null) {
+ for (int i = 0; i < typeMaps.size(); ++i) {
+ if (typeMaps.get(i).getPrefix().equals(memberType.getPrefix())) {
+ type = (NamedType)typeMaps.get(i).getType(memberType.getLocalPart());
+ break;
+ }
+ }
+ }
+ } else if (obj instanceof Union) {
+ // TODO: Exception for the current milestone
+ }
+
+ return type;
+ }
+
+ public static AddressType getCorbaAddressType(Bus bus, EndpointReferenceType endpointRef) {
+ AddressType addrType = null;
+ try {
+ Port wsdlPort = EndpointReferenceUtils.getPort(bus.getWSDLManager(),
+ endpointRef);
+
+ List extElements = wsdlPort.getExtensibilityElements();
+ for (int i = 0; i < extElements.size(); ++i) {
+ Object e = extElements.get(i);
+ if (e instanceof AddressType) {
+ addrType = (AddressType) e;
+ break;
+ }
+ }
+ } catch (java.lang.Exception ex) {
+ throw new CorbaBindingException("Unable to obtain corba address information", ex);
+ }
+
+ return addrType;
+ }
+
+ public static BindingType getCorbaBindingType(Bus bus, EndpointReferenceType endpointRef) {
+ BindingType bindType = null;
+ try {
+ Port wsdlPort = EndpointReferenceUtils.getPort(bus.getWSDLManager(), endpointRef);
+ Binding wsdlBinding = wsdlPort.getBinding();
+
+ List extElements = wsdlBinding.getExtensibilityElements();
+ for (int i = 0; i < extElements.size(); ++i) {
+ Object e = extElements.get(i);
+ if (e instanceof BindingType) {
+ bindType = (BindingType) e;
+ break;
+ }
+ }
+ } catch (java.lang.Exception ex) {
+ throw new CorbaBindingException("Unable to obtain corba binding information", ex);
+ }
+ return bindType;
+ }
+
+ public static OperationType getCorbaOperationType(String opName,
+ Bus bus,
+ EndpointReferenceType endpoint) {
+ try {
+ WSDLHelper helper = new WSDLHelper();
+ Port port = EndpointReferenceUtils.getPort(bus.getWSDLManager(), endpoint);
+ BindingOperation bindingOp = helper.getBindingOperation(port.getBinding(), opName);
+
+ OperationType operation = null;
+ List extElements = bindingOp.getExtensibilityElements();
+ for (int i = 0; i < extElements.size(); ++i) {
+ Object e = extElements.get(i);
+ if (e instanceof OperationType) {
+ operation = (OperationType) e;
+ break;
+ }
+ }
+ return operation;
+ } catch (java.lang.Exception ex) {
+ throw new CorbaBindingException("Unable to obtain corba operation information", ex);
+ }
+ }
+
+ public static void exportObjectReferenceToFile(org.omg.CORBA.Object obj, ORB orb, String iorFile)
+ throws IOException {
+ String ref = orb.object_to_string(obj);
+ FileOutputStream file = new FileOutputStream(iorFile);
+ PrintWriter out = new PrintWriter(file);
+ out.println(ref);
+ out.flush();
+ file.close();
+ }
+
+ static {
+ PRIMITIVE_TYPECODES.put(CorbaConstants.NT_CORBA_BOOLEAN, TCKind.from_int(TCKind._tk_boolean));
+ PRIMITIVE_TYPECODES.put(CorbaConstants.NT_CORBA_CHAR, TCKind.from_int(TCKind._tk_char));
+ PRIMITIVE_TYPECODES.put(CorbaConstants.NT_CORBA_WCHAR, TCKind.from_int(TCKind._tk_wchar));
+ PRIMITIVE_TYPECODES.put(CorbaConstants.NT_CORBA_OCTET, TCKind.from_int(TCKind._tk_octet));
+ PRIMITIVE_TYPECODES.put(CorbaConstants.NT_CORBA_SHORT, TCKind.from_int(TCKind._tk_short));
+ PRIMITIVE_TYPECODES.put(CorbaConstants.NT_CORBA_LONG, TCKind.from_int(TCKind._tk_long));
+ PRIMITIVE_TYPECODES.put(CorbaConstants.NT_CORBA_ULONG, TCKind.from_int(TCKind._tk_ulong));
+ PRIMITIVE_TYPECODES.put(CorbaConstants.NT_CORBA_LONGLONG, TCKind.from_int(TCKind._tk_longlong));
+ PRIMITIVE_TYPECODES.put(CorbaConstants.NT_CORBA_ULONGLONG, TCKind.from_int(TCKind._tk_ulonglong));
+ PRIMITIVE_TYPECODES.put(CorbaConstants.NT_CORBA_FLOAT, TCKind.from_int(TCKind._tk_float));
+ PRIMITIVE_TYPECODES.put(CorbaConstants.NT_CORBA_DOUBLE, TCKind.from_int(TCKind._tk_double));
+ PRIMITIVE_TYPECODES.put(CorbaConstants.NT_CORBA_STRING, TCKind.from_int(TCKind._tk_string));
+ PRIMITIVE_TYPECODES.put(CorbaConstants.NT_CORBA_WSTRING, TCKind.from_int(TCKind._tk_wstring));
+ }
+}
\ No newline at end of file
Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/Messages.properties?rev=413964&view=auto
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/Messages.properties (added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/Messages.properties Tue Jun 13 12:40:51 2006
@@ -0,0 +1 @@
+// TODO: Add messages here for exceptions
Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaAddressExtensionHelper.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaAddressExtensionHelper.java?rev=413964&view=auto
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaAddressExtensionHelper.java (added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaAddressExtensionHelper.java Tue Jun 13 12:40:51 2006
@@ -0,0 +1,65 @@
+/**
+ *
+ * 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.apache.schemas.yoko.bindings.corba.AddressType;
+
+public class CorbaAddressExtensionHelper implements ExtensionDeserializer {
+
+ private static String corbaPrefix = "corba";
+
+ private static String corbaURI = "http://schemas.apache.org/yoko/bindings/corba";
+
+ public CorbaAddressExtensionHelper() {
+ }
+
+ public static void addExtension(ExtensionRegistry registry,
+ Class parentType, String element) {
+ QName extQName = new QName(corbaURI, element, corbaPrefix);
+ CorbaAddressExtensionHelper helper = new CorbaAddressExtensionHelper();
+
+ registry.registerDeserializer(parentType, extQName, helper);
+ }
+
+ public ExtensibilityElement unmarshall(Class parentType, QName elementType,
+ Element el, Definition def, ExtensionRegistry extReg)
+ throws WSDLException {
+ AddressType addrType = new AddressType();
+ addrType.setElementType(elementType);
+
+ // Store the location held in the address element
+ NamedNodeMap addrAttributes = el.getAttributes();
+ for (int i = 0; i < addrAttributes.getLength(); ++i) {
+ if (addrAttributes.item(i).getNodeName().equals("location")) {
+ addrType.setLocation(addrAttributes.item(i).getNodeValue());
+ }
+ }
+
+ return addrType;
+ }
+}
\ No newline at end of file
Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaBindingExtensionHelper.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaBindingExtensionHelper.java?rev=413964&view=auto
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaBindingExtensionHelper.java (added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaBindingExtensionHelper.java Tue Jun 13 12:40:51 2006
@@ -0,0 +1,70 @@
+/**
+ *
+ * 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.apache.schemas.yoko.bindings.corba.BindingType;
+
+public class CorbaBindingExtensionHelper implements ExtensionDeserializer {
+ private static String corbaPrefix = "corba";
+
+ private static String corbaURI = "http://schemas.apache.org/yoko/bindings/corba";
+
+ public CorbaBindingExtensionHelper() {
+ }
+
+ public static void addExtension(ExtensionRegistry registry,
+ Class parentType, String element) {
+ QName extQName = new QName(corbaURI, element, corbaPrefix);
+ CorbaBindingExtensionHelper helper = new CorbaBindingExtensionHelper();
+
+ registry.registerDeserializer(parentType, extQName, helper);
+ }
+
+ public ExtensibilityElement unmarshall(Class parentType, QName elementType,
+ Element el, Definition def, ExtensionRegistry extReg)
+ throws WSDLException {
+
+ BindingType bindType = new BindingType();
+ bindType.setElementType(elementType);
+
+ // Store the repository ids of the interface and bases
+ NamedNodeMap bindAttributes = el.getAttributes();
+ for (int i = 0; i < bindAttributes.getLength(); ++i) {
+ if (bindAttributes.item(i).getNodeName().equals("repositoryID")) {
+ bindType.setRepositoryID(bindAttributes.item(i).getNodeValue());
+ } else if (bindAttributes.item(i).getNodeName().equals("bases")) {
+ String allBases = bindAttributes.item(i).getNodeValue();
+ String[] bases = allBases.split(" ");
+ for (int j = 0; j < bases.length; ++j) {
+ bindType.getBases().add(bases[j]);
+ }
+ }
+ }
+
+ return bindType;
+ }
+}
Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaOperationExtensionHelper.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaOperationExtensionHelper.java?rev=413964&view=auto
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaOperationExtensionHelper.java (added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/extensions/CorbaOperationExtensionHelper.java Tue Jun 13 12:40:51 2006
@@ -0,0 +1,147 @@
+/**
+ *
+ * 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.ArgType;
+import org.apache.schemas.yoko.bindings.corba.ModeType;
+import org.apache.schemas.yoko.bindings.corba.OperationType;
+import org.apache.schemas.yoko.bindings.corba.ParamType;
+import org.apache.schemas.yoko.bindings.corba.RaisesType;
+
+import org.apache.yoko.bindings.corba.CorbaConstants;
+
+public class CorbaOperationExtensionHelper implements ExtensionDeserializer {
+
+ private static String corbaPrefix = "corba";
+
+ private static String corbaURI = "http://schemas.apache.org/yoko/bindings/corba";
+
+ public CorbaOperationExtensionHelper() {
+ }
+
+ public static void addExtension(ExtensionRegistry registry,
+ Class parentType, String element) {
+ QName extQName = new QName(corbaURI, element, corbaPrefix);
+ CorbaOperationExtensionHelper helper = new CorbaOperationExtensionHelper();
+
+ registry.registerDeserializer(parentType, extQName, helper);
+ }
+
+ public ExtensibilityElement unmarshall(Class parentType, QName elementType,
+ Element el, Definition def, ExtensionRegistry extReg)
+ throws WSDLException {
+
+ OperationType opType = new OperationType();
+
+ // Store the operation name
+ NamedNodeMap opAttributes = el.getAttributes();
+ for (int i = 0; i < opAttributes.getLength(); ++i) {
+ if (opAttributes.item(i).getNodeName().equals("name")) {
+ opType.setName(opAttributes.item(i).getNodeValue());
+ }
+ }
+
+ // Store the operations parameters, return value, and raises
+ NodeList opChildNodes = el.getChildNodes();
+ for (int i = 0; i < opChildNodes.getLength(); ++i) {
+ Node currentNode = opChildNodes.item(i);
+
+ if (currentNode.getNodeName().equals("corba:param")) {
+ ParamType param = new ParamType();
+ NamedNodeMap paramAttributes = currentNode.getAttributes();
+
+ for (int j = 0; j < paramAttributes.getLength(); ++j) {
+ Node paramAttrNode = paramAttributes.item(j);
+ if (paramAttrNode.getNodeName().equals("name")) {
+ param.setName(paramAttrNode.getNodeValue());
+ } else if (paramAttrNode.getNodeName().equals("mode")) {
+ param.setMode(ModeType.fromValue(paramAttrNode
+ .getNodeValue()));
+ } else if (paramAttrNode.getNodeName().equals("idltype")) {
+ String idlType = paramAttrNode.getNodeValue();
+ int seperatorIndex = idlType.indexOf(':');
+ String prefix = idlType
+ .substring(0, seperatorIndex - 1);
+ String localPart = idlType.substring(
+ seperatorIndex + 1, idlType.length());
+ assert prefix.equals(CorbaConstants.NP_WSDL_CORBA);
+ param
+ .setIdltype(new QName(
+ CorbaConstants.NU_WSDL_CORBA,
+ localPart, prefix));
+ }
+ }
+ opType.getParam().add(param);
+ } else if (currentNode.getNodeName().equals("corba:return")) {
+ ArgType ret = new ArgType();
+ NamedNodeMap retAttributes = currentNode.getAttributes();
+
+ for (int j = 0; j < retAttributes.getLength(); ++j) {
+ Node retAttrNode = retAttributes.item(j);
+ if (retAttrNode.getNodeName().equals("idltype")) {
+ String idlType = retAttrNode.getNodeValue();
+ int seperatorIndex = idlType.indexOf(':');
+ String prefix = idlType
+ .substring(0, seperatorIndex - 1);
+ String localPart = idlType.substring(
+ seperatorIndex + 1, idlType.length());
+ assert prefix.equals(CorbaConstants.NP_WSDL_CORBA);
+ ret.setIdltype(new QName(CorbaConstants.NU_WSDL_CORBA,
+ localPart, prefix));
+ }
+ }
+ opType.setReturn(ret);
+ } else if (currentNode.getNodeName().equals("corba:raises")) {
+ RaisesType raises = new RaisesType();
+ NamedNodeMap raiseAttributes = currentNode.getAttributes();
+
+ for (int j = 0; j < raiseAttributes.getLength(); ++j) {
+ Node raiseAttrNode = raiseAttributes.item(j);
+ if (raiseAttrNode.getNodeName().equals("exception")) {
+ String idlType = raiseAttrNode.getNodeValue();
+ int seperatorIndex = idlType.indexOf(':');
+ String prefix = idlType
+ .substring(0, seperatorIndex - 1);
+ String localPart = idlType.substring(
+ seperatorIndex + 1, idlType.length());
+ assert prefix.equals(CorbaConstants.NP_WSDL_CORBA);
+ raises
+ .setException(new QName(
+ CorbaConstants.NU_WSDL_CORBA,
+ localPart, prefix));
+ }
+ }
+ opType.getRaises().add(raises);
+ }
+ // anything else we are not interested in at the moment
+ }
+ return opType;
+ }
+}