You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2008/06/16 23:58:13 UTC
svn commit: r668328 [2/8] - in /incubator/tuscany/java/sca/modules: ./
binding-corba-runtime/ binding-corba-runtime/src/
binding-corba-runtime/src/main/ binding-corba-runtime/src/main/java/
binding-corba-runtime/src/main/java/org/ binding-corba-runtime...
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/exceptions/RequestConfigurationException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/exceptions/RequestConfigurationException.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/exceptions/RequestConfigurationException.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/exceptions/RequestConfigurationException.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,39 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.exceptions;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RequestConfigurationException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+ private String objectId;
+
+ public RequestConfigurationException(String message, String objectId) {
+ super(message + ", object id was: " + objectId);
+ this.objectId = objectId;
+ }
+
+ public String getType() {
+ return objectId;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/exceptions/RequestConfigurationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/exceptions/RequestConfigurationException.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,180 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.reference;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sca.binding.corba.impl.exceptions.CorbaException;
+import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException;
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTree;
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeCreator;
+import org.apache.tuscany.sca.binding.corba.impl.types.util.TypeHelpersProxy;
+import org.omg.CORBA.BAD_OPERATION;
+import org.omg.CORBA.Object;
+import org.omg.CORBA.SystemException;
+import org.omg.CORBA.portable.ApplicationException;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.ObjectImpl;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$ Represents single CORBA request
+ */
+public class DynaCorbaRequest {
+
+ private TypeTree returnTree;
+ private List<TypeTree> arguments = new ArrayList<TypeTree>();
+ private Map<String, TypeTree> exceptions = new HashMap<String, TypeTree>();
+ private OutputStream outputStream;
+ private ObjectImpl remoteObject;
+ private String operation;
+
+ /**
+ * Creates request.
+ *
+ * @param ObjectremoteObject
+ * remote object reference
+ * @param operation
+ * operation to invoke
+ */
+ public DynaCorbaRequest(Object remoteObject, String operation) {
+ outputStream = ((ObjectImpl) remoteObject)._request(operation, true);
+ this.remoteObject = (ObjectImpl) remoteObject;
+ this.operation = operation;
+
+ }
+
+ /**
+ * Adds operation argument
+ *
+ * @param argument
+ */
+ public void addArgument(java.lang.Object argument) {
+ TypeTree tree = TypeTreeCreator.createTypeTree(argument.getClass());
+ TypeHelpersProxy.write(tree.getRootNode(), outputStream, argument);
+ }
+
+ /**
+ * Sets return type for operation
+ *
+ * @param forClass
+ */
+ public void setOutputType(Class<?> forClass) {
+ returnTree = TypeTreeCreator.createTypeTree(forClass);
+ }
+
+ private String getExceptionId(Class<?> forClass) {
+ String result = forClass.getName().replace('.', '/');
+ result = result.replaceAll("Package", "");
+ if (result.endsWith("Exception")) {
+ result = result
+ .substring(0, result.length() - "Exception".length());
+ }
+ result = "IDL:" + result + ":1.0";
+ return result;
+ }
+
+ /**
+ * Configures possible exceptions
+ *
+ * @param forClass
+ */
+ public void addExceptionType(Class<?> forClass) {
+ TypeTree tree = TypeTreeCreator.createTypeTree(forClass);
+ String exceptionId = getExceptionId(forClass);
+ exceptions.put(exceptionId, tree);
+ }
+
+ /**
+ * Handles application excpeition.
+ *
+ * @param ae
+ * occured exception
+ * @throws Exception
+ */
+ private void handleApplicationException(ApplicationException ae)
+ throws Exception {
+ try {
+ if (exceptions.size() == 0) {
+ RequestConfigurationException exception = new RequestConfigurationException(
+ "ApplicationException occured, but no exception type was specified.",
+ ae.getId());
+ throw exception;
+ }
+ InputStream is = ae.getInputStream();
+ String exceptionId = is.read_string();
+ TypeTree tree = exceptions.get(exceptionId);
+ if (tree == null) {
+ RequestConfigurationException exception = new RequestConfigurationException(
+ "ApplicationException occured, but no such exception was defined",
+ ae.getId());
+ throw exception;
+ } else {
+ Exception ex = (Exception) TypeHelpersProxy.read(tree
+ .getRootNode(), is);
+ throw ex;
+ }
+ } catch (Exception e) {
+ throw e;
+ }
+ }
+
+ /**
+ * Handles exceptions generated by CORBA API
+ *
+ * @param se
+ */
+ private void handleSystemException(SystemException se) throws Exception {
+ if (se instanceof BAD_OPERATION) {
+ throw new CorbaException("Bad operation name: " + operation, se);
+ } else {
+ // TODO: handle more system exception types
+ throw new CorbaException(se.getMessage(), se);
+ }
+ }
+
+ /**
+ * Invokes previously configured request
+ *
+ * @return
+ */
+ public DynaCorbaResponse invoke() throws Exception {
+ DynaCorbaResponse response = new DynaCorbaResponse();
+ InputStream is = null;
+ try {
+ is = remoteObject._invoke(outputStream);
+ if (is != null && returnTree != null) {
+ response.setContent(TypeHelpersProxy.read(returnTree
+ .getRootNode(), is));
+ }
+ } catch (ApplicationException ae) {
+ handleApplicationException(ae);
+ } catch (SystemException se) {
+ handleSystemException(se);
+ } catch (Exception e) {
+ throw e;
+ }
+ return response;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaResponse.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaResponse.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaResponse.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaResponse.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,39 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.reference;
+
+/**
+ * @version $Rev$ $Date$
+ * Holder for content returned from DynaCorbaRequest
+ *
+ */
+public class DynaCorbaResponse {
+
+ private Object content;
+
+ public Object getContent() {
+ return content;
+ }
+
+ public void setContent(Object content) {
+ this.content = content;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaResponse.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaResponse.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceInstanceCreator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceInstanceCreator.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceInstanceCreator.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceInstanceCreator.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,72 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.reference;
+
+import java.lang.reflect.Method;
+
+import net.sf.cglib.proxy.Callback;
+import net.sf.cglib.proxy.CallbackFilter;
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.NoOp;
+
+import org.omg.CORBA.Object;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InterfaceInstanceCreator {
+
+ private static final CallbackFilter FILTER = new CallbackFilter() {
+ public int accept(Method method) {
+ return 1;
+ }
+ };
+
+ /**
+ * Dynamically creates instance of user defined interface. Instance is
+ * enhanced by RemoteMethodInterceptor
+ *
+ * @param reference
+ * CORBA reference
+ * @param forClass
+ * user defined interface
+ * @return dynamic implementation instance
+ */
+ public static java.lang.Object createInstance(Object reference,
+ Class<?> forClass) {
+ java.lang.Object result = null;
+ try {
+ Enhancer enhancer = new Enhancer();
+ enhancer.setInterfaces(new Class[] { forClass });
+ enhancer.setCallbackFilter(FILTER);
+ enhancer.setCallbackTypes(new Class[] { NoOp.class,
+ MethodInterceptor.class });
+ Class<?> newClass = enhancer.createClass();
+ Enhancer.registerStaticCallbacks(newClass, new Callback[] {
+ NoOp.INSTANCE, new InterfaceMethodInterceptor(reference) });
+ result = newClass.newInstance();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceInstanceCreator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceInstanceCreator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceMethodInterceptor.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceMethodInterceptor.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceMethodInterceptor.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,61 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.reference;
+
+import java.lang.reflect.Method;
+
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+
+import org.omg.CORBA.Object;
+
+/**
+ * @version $Rev$ $Date$
+ * Interceptor for CORBA reference methods
+ */
+public class InterfaceMethodInterceptor implements MethodInterceptor {
+
+ private Object reference;
+
+ public InterfaceMethodInterceptor(Object reference) {
+ this.reference = reference;
+ }
+
+ /**
+ * Create and execute DynaCorbaRequest instance, basing on intercepted
+ * method arguments, return types, exceptions
+ */
+ public java.lang.Object intercept(java.lang.Object object, Method method,
+ java.lang.Object[] arguments, MethodProxy arg3) throws Throwable {
+ DynaCorbaRequest request = new DynaCorbaRequest(reference, method
+ .getName());
+ for (int i = 0; i < arguments.length; i++) {
+ request.addArgument(arguments[i]);
+ }
+ request.setOutputType(method.getReturnType());
+ Class<?>[] exceptions = method.getExceptionTypes();
+ for (int i = 0; i < exceptions.length; i++) {
+ request.addExceptionType(exceptions[i]);
+ }
+ DynaCorbaResponse response = request.invoke();
+ return response.getContent();
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceMethodInterceptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/InterfaceMethodInterceptor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/NodeType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/NodeType.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/NodeType.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/NodeType.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,28 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types;
+
+/**
+ * @version $Rev$ $Date$
+ * Types of CORBA objects.
+ */
+public enum NodeType {
+ primitive, struct, union, array, sequence, reference
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/NodeType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/NodeType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTree.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTree.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTree.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTree.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,76 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @version $Rev$ $Date$
+ * Helper tree for Java object hierarchy. It's closer to CORBA types structure
+ * than plain Java hierarchy - it helps reading and writing complex structures.
+ */
+public class TypeTree {
+
+ private Map<Class<?>, TypeTreeNode> typesUsed = new HashMap<Class<?>, TypeTreeNode>();
+ private TypeTreeNode rootNode;
+
+ /**
+ * Intent was to cache previously computed type trees. In practice it caused
+ * a bug, and it's not being used right now. TODO: enable type trees caching
+ *
+ * @param forClass
+ * @param node
+ */
+ public void addUsedType(Class<?> forClass, TypeTreeNode node) {
+ typesUsed.put(forClass, node);
+ }
+
+ /**
+ * Returns node for previously created tree, it's getter for nodes added by
+ * addUsedType method. Not in use right now. TODO: enable type trees caching
+ *
+ * @param forClass
+ * @return
+ */
+ public TypeTreeNode getNodeForType(Class<?> forClass) {
+ return typesUsed.get(forClass);
+ }
+
+ /**
+ * Returns root node.
+ *
+ * @return root of type tree
+ */
+ public TypeTreeNode getRootNode() {
+ return rootNode;
+ }
+
+ /**
+ * Sets root of the type tree.
+ *
+ * @param rootNode
+ * root node.
+ */
+ public void setRootNode(TypeTreeNode rootNode) {
+ this.rootNode = rootNode;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTree.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTree.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,224 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @version $Rev$ $Date$
+ * Creator of types tree.
+ *
+ */
+public class TypeTreeCreator {
+
+ /**
+ * Helps to determine if type is a primitive.
+ */
+ private static List<Class<?>> primitives = new ArrayList<Class<?>>();
+
+ static {
+ primitives.add(boolean.class);
+ primitives.add(byte.class);
+ primitives.add(short.class);
+ primitives.add(int.class);
+ primitives.add(long.class);
+ primitives.add(double.class);
+ primitives.add(float.class);
+ primitives.add(char.class);
+ primitives.add(String.class);
+ primitives.add(Boolean.class);
+ primitives.add(Byte.class);
+ primitives.add(Short.class);
+ primitives.add(Integer.class);
+ primitives.add(Long.class);
+ primitives.add(Double.class);
+ primitives.add(Float.class);
+ primitives.add(Character.class);
+ }
+
+ /**
+ * Creates class for given string argument.
+ *
+ * @param name
+ * name of type
+ * @return type
+ */
+ private static Class<?> createClassFromString(String name) {
+ Class<?> result = null;
+ try {
+ if (name.length() == 1) {
+ // primitives
+ switch (name.charAt(0)) {
+ case 'Z':
+ result = boolean.class;
+ break;
+ case 'C':
+ result = char.class;
+ break;
+ case 'B':
+ result = byte.class;
+ break;
+ case 'S':
+ result = short.class;
+ break;
+ case 'I':
+ result = int.class;
+ break;
+ case 'J':
+ result = long.class;
+ break;
+ case 'F':
+ result = float.class;
+ break;
+ case 'D':
+ result = double.class;
+ break;
+ }
+ } else {
+ // class
+ name = name.substring(1, name.length() - 1);
+ result = Class.forName(name);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ /**
+ * Reduces dimension of array.
+ *
+ * @param forClass
+ * array class
+ * @return reduced array
+ */
+ private static Class<?> reduceArrayDimension(Class<?> forClass) {
+ String name = forClass.getName();
+ try {
+ String reduced = name.substring(1, name.length());
+ if (reduced.startsWith("[")) {
+ // reduced class is still an array
+ return Class.forName(reduced);
+ } else {
+ // reduced class may be primitive or class
+ return createClassFromString(reduced);
+ }
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * Creates tree for given type.
+ *
+ * @param forClass
+ * @return type tree
+ */
+ public static TypeTree createTypeTree(Class<?> forClass) {
+ TypeTree tree = new TypeTree();
+ TypeTreeNode rootNode = null;
+ rootNode = inspectClassHierarchy(forClass, tree);
+ tree.setRootNode(rootNode);
+ return tree;
+
+ }
+
+ /**
+ * Recurrent method which builds type tree.
+ *
+ * @param forClass
+ * @param tree
+ * @return
+ */
+ private static TypeTreeNode inspectClassHierarchy(Class<?> forClass,
+ TypeTree tree) {
+ // //remains of type tree caching
+ // TypeTreeNode existingNode = tree.getNodeForType(forClass);
+ // if (existingNode != null) {
+ // return existingNode;
+ // }
+
+ TypeTreeNode node = createTypeNode(forClass);
+ NodeType nodeType = node.getNodeType();
+ TypeTreeNode[] children = null;
+
+ // //remains of type tree caching
+ // tree.addUsedType(forClass, node);
+
+ if (nodeType.equals(NodeType.primitive)) {
+ // stop condition for recurrent method
+ } else if (nodeType.equals(NodeType.array)) {
+ // similar to sequence, but with fixed array length
+ // TODO: determine how array length will be declared
+ } else if (nodeType.equals(NodeType.sequence)) {
+ // reducing sequence dimension
+ Class<?> reduced = reduceArrayDimension(node.getJavaClass());
+ children = new TypeTreeNode[1];
+ children[0] = inspectClassHierarchy(reduced, tree);
+ } else if (nodeType.equals(NodeType.struct)) {
+ // inspect types for every structure member
+ Field[] fields = node.getJavaClass().getFields();
+ children = new TypeTreeNode[fields.length];
+ for (int i = 0; i < fields.length; i++) {
+ Class<?> field = fields[i].getType();
+ TypeTreeNode child = inspectClassHierarchy(field, tree);
+ child.setName(fields[i].getName());
+ children[i] = child;
+ }
+ } else if (nodeType.equals(NodeType.union)) {
+ // TODO: unions
+ } else if (nodeType.equals(NodeType.reference)) {
+ // TODO: CORBA references
+ }
+
+ node.setChildren(children);
+ return node;
+ }
+
+ /**
+ * Creating and configuring TypeTreeNode for given class.
+ *
+ * @param forClass
+ * class
+ * @return node
+ */
+ private static TypeTreeNode createTypeNode(Class<?> forClass) {
+ TypeTreeNode node = new TypeTreeNode();
+ if (forClass.isArray()) {
+ node.setNodeType(NodeType.sequence);
+ node.setJavaClass(forClass);
+ } else if (primitives.contains(forClass)) {
+ node.setNodeType(NodeType.primitive);
+ node.setJavaClass(forClass);
+ node.setChildren(null);
+ } else if (forClass.isInterface()) {
+ node.setNodeType(NodeType.reference);
+ node.setJavaClass(forClass);
+ node.setChildren(null);
+ } else {
+ node.setNodeType(NodeType.struct);
+ node.setJavaClass(forClass);
+ }
+ return node;
+ }
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeNode.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeNode.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeNode.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeNode.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,66 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types;
+
+/**
+ * @version $Rev$ $Date$
+ * Represents single tree node.
+ *
+ */
+public class TypeTreeNode {
+
+ private NodeType nodeType;
+ private TypeTreeNode[] children;
+ private Class<?> javaClass;
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public NodeType getNodeType() {
+ return nodeType;
+ }
+
+ public void setNodeType(NodeType nodeType) {
+ this.nodeType = nodeType;
+ }
+
+ public TypeTreeNode[] getChildren() {
+ return children;
+ }
+
+ public void setChildren(TypeTreeNode[] children) {
+ this.children = children;
+ }
+
+ public Class<?> getJavaClass() {
+ return javaClass;
+ }
+
+ public void setJavaClass(Class<?> javaClass) {
+ this.javaClass = javaClass;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeNode.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ArrayTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ArrayTypeHelper.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ArrayTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ArrayTypeHelper.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+/**
+ * @version $Rev$ $Date$
+ */
+public class ArrayTypeHelper implements TypeHelper {
+
+ public TypeCode getType(TypeTreeNode node) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object read(TypeTreeNode node, InputStream is) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void write(TypeTreeNode node, OutputStream os, Object data) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ArrayTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ArrayTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/BooleanTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/BooleanTypeHelper.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/BooleanTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/BooleanTypeHelper.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,45 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BooleanTypeHelper implements TypeHelper {
+
+ public TypeCode getType(TypeTreeNode node) {
+ return ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.from_int(8));
+ }
+
+ public Object read(TypeTreeNode node, InputStream is) {
+ return is.read_boolean();
+ }
+
+ public void write(TypeTreeNode node, OutputStream os, Object data) {
+ os.write_boolean((Boolean) data);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/BooleanTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/BooleanTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ByteTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ByteTypeHelper.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ByteTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ByteTypeHelper.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,45 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ByteTypeHelper implements TypeHelper {
+
+ public TypeCode getType(TypeTreeNode node) {
+ return ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.from_int(10));
+ }
+
+ public Object read(TypeTreeNode node, InputStream is) {
+ return is.read_octet();
+ }
+
+ public void write(TypeTreeNode node, OutputStream os, Object data) {
+ os.write_octet((Byte) data);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ByteTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ByteTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/CharTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/CharTypeHelper.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/CharTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/CharTypeHelper.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,45 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CharTypeHelper implements TypeHelper {
+
+ public TypeCode getType(TypeTreeNode node) {
+ return ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.from_int(9));
+ }
+
+ public Object read(TypeTreeNode node, InputStream is) {
+ return is.read_char();
+ }
+
+ public void write(TypeTreeNode node, OutputStream os, Object data) {
+ os.write_char((Character) data);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/CharTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/CharTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/DoubleTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/DoubleTypeHelper.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/DoubleTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/DoubleTypeHelper.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,45 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DoubleTypeHelper implements TypeHelper {
+
+ public TypeCode getType(TypeTreeNode node) {
+ return ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.from_int(7));
+ }
+
+ public Object read(TypeTreeNode node, InputStream is) {
+ return is.read_double();
+ }
+
+ public void write(TypeTreeNode node, OutputStream os, Object data) {
+ os.write_double((Double) data);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/DoubleTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/DoubleTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/FloatTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/FloatTypeHelper.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/FloatTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/FloatTypeHelper.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,45 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class FloatTypeHelper implements TypeHelper {
+
+ public TypeCode getType(TypeTreeNode node) {
+ return ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.from_int(6));
+ }
+
+ public Object read(TypeTreeNode node, InputStream is) {
+ return is.read_float();
+ }
+
+ public void write(TypeTreeNode node, OutputStream os, Object data) {
+ os.write_float((Float) data);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/FloatTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/FloatTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/IntTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/IntTypeHelper.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/IntTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/IntTypeHelper.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,45 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IntTypeHelper implements TypeHelper {
+
+ public TypeCode getType(TypeTreeNode node) {
+ return ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.from_int(3));
+ }
+
+ public Object read(TypeTreeNode node, InputStream is) {
+ return is.read_long();
+ }
+
+ public void write(TypeTreeNode node, OutputStream os, Object data) {
+ os.write_long((Integer) data);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/IntTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/IntTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/LongTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/LongTypeHelper.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/LongTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/LongTypeHelper.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LongTypeHelper implements TypeHelper {
+
+ public TypeCode getType(TypeTreeNode node) {
+ return ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.from_int(23));
+ }
+
+ public Object read(TypeTreeNode node, InputStream is) {
+ return is.read_longlong();
+ }
+
+ public void write(TypeTreeNode node, OutputStream os, Object data) {
+ os.write_longlong((Long) data);
+ }
+
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/LongTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/LongTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ReferenceTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ReferenceTypeHelper.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ReferenceTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ReferenceTypeHelper.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import org.apache.tuscany.sca.binding.corba.impl.reference.InterfaceInstanceCreator;
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.Object;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceTypeHelper implements TypeHelper {
+
+ public TypeCode getType(TypeTreeNode node) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public java.lang.Object read(TypeTreeNode node, InputStream is) {
+ Object reference = is.read_Object();
+ return (java.lang.Object) InterfaceInstanceCreator.createInstance(reference, node.getJavaClass());
+ }
+
+ public void write(TypeTreeNode node, OutputStream os, java.lang.Object data) {
+ os.write_Object((Object) data);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ReferenceTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ReferenceTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/SequenceTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/SequenceTypeHelper.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/SequenceTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/SequenceTypeHelper.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,83 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SequenceTypeHelper implements TypeHelper {
+
+ public TypeCode getType(TypeTreeNode node) {
+ TypeCode typeCode =
+ org.omg.CORBA.ORB.init().create_alias_tc(
+ node.getJavaClass().getSimpleName(),
+ node.getJavaClass().getSimpleName(),
+ org.omg.CORBA.ORB.init().create_sequence_tc(0,
+ TypeHelpersProxy.getType(node.getChildren()[0])));
+ return typeCode;
+ }
+
+ public Object read(TypeTreeNode node, InputStream is) {
+ Object sequence = null;
+ try {
+ int size = is.read_long();
+ sequence = Array.newInstance(node.getChildren()[0].getJavaClass(),
+ size);
+ for (int i = 0; i < size; i++) {
+ Array.set(sequence, i, TypeHelpersProxy.read(
+ node.getChildren()[0], is));
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return sequence;
+ }
+
+ public void write(TypeTreeNode node, OutputStream os, Object data) {
+ int sum = 0;
+ // determine length of array
+ List<Object> array = new ArrayList<Object>();
+ while (true) {
+ try {
+ array.add(Array.get(data, sum));
+ sum++;
+ } catch (ArrayIndexOutOfBoundsException e) {
+ break;
+ }
+ }
+ os.write_long(sum);
+ Iterator<Object> iter = array.iterator();
+ while (iter.hasNext()) {
+ Object elem = iter.next();
+ TypeHelpersProxy.write(node.getChildren()[0], os, elem);
+ }
+
+ }
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/SequenceTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/SequenceTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ShortTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ShortTypeHelper.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ShortTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ShortTypeHelper.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ShortTypeHelper implements TypeHelper {
+
+ public TypeCode getType(TypeTreeNode node) {
+ return ORB.init().get_primitive_tc(org.omg.CORBA.TCKind.from_int(2));
+ }
+
+ public Object read(TypeTreeNode node, InputStream is) {
+ return is.read_short();
+ }
+
+ public void write(TypeTreeNode node, OutputStream os, Object data) {
+ os.write_short((Short) data);
+ }
+
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ShortTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/ShortTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StringTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StringTypeHelper.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StringTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StringTypeHelper.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StringTypeHelper implements TypeHelper {
+
+ public TypeCode getType(TypeTreeNode node) {
+ return ORB.init().create_string_tc(0);
+ }
+
+ public Object read(TypeTreeNode node, InputStream is) {
+ return is.read_string();
+ }
+
+ public void write(TypeTreeNode node, OutputStream os, Object data) {
+ os.write_string((String) data);
+ }
+
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StringTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StringTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StructTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StructTypeHelper.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StructTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StructTypeHelper.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,90 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import java.lang.reflect.Field;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.StructMember;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StructTypeHelper implements TypeHelper {
+
+ public TypeCode getType(TypeTreeNode node) {
+ TypeTreeNode[] children = node.getChildren();
+ if (children != null) {
+ StructMember[] members = new StructMember[children.length];
+ for (int i = 0; i < children.length; i++) {
+ members[i] = new StructMember(children[i].getJavaClass()
+ .getSimpleName(),
+ TypeHelpersProxy.getType(children[i]), null);
+ }
+ TypeCode result = org.omg.CORBA.ORB.init().create_struct_tc(
+ node.getJavaClass().getSimpleName(),
+ node.getJavaClass().getSimpleName(), members);
+ return result;
+ } else {
+ return null;
+ }
+ }
+
+ public Object read(TypeTreeNode node, InputStream is) {
+ TypeTreeNode[] children = node.getChildren();
+ Object result = null;
+ if (children != null) {
+ try {
+ result = node.getJavaClass().newInstance();
+ for (int i = 0; i < children.length; i++) {
+ Object childResult = TypeHelpersProxy.read(children[i], is);
+ Field childField = result.getClass().getField(
+ children[i].getName());
+ childField.set(result, childResult);
+ }
+ } catch (Exception e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ }
+ return result;
+ }
+
+ public void write(TypeTreeNode node, OutputStream os, Object data) {
+ TypeTreeNode[] children = node.getChildren();
+ if (children != null) {
+ try {
+ for (int i = 0; i < children.length; i++) {
+ Field childField = node.getJavaClass().getField(
+ children[i].getName());
+ TypeHelpersProxy.write(children[i], os, childField
+ .get(data));
+ }
+ } catch (Exception e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StructTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/StructTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelper.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelper.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,55 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface TypeHelper {
+
+ /**
+ * Gets type definition for CORBA API.
+ * @param node
+ * @return
+ */
+ TypeCode getType(TypeTreeNode node);
+
+ /**
+ * Reads CORBA object
+ * @param node
+ * @param is
+ * @return
+ */
+ Object read(TypeTreeNode node, InputStream is);
+
+ /**
+ * Writes CORBA object
+ * @param node
+ * @param os
+ * @param data
+ */
+ void write(TypeTreeNode node, OutputStream os, Object data);
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelpersProxy.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelpersProxy.java?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelpersProxy.java (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelpersProxy.java Mon Jun 16 14:58:09 2008
@@ -0,0 +1,132 @@
+/*
+ * 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.tuscany.sca.binding.corba.impl.types.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.NodeType;
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeNode;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * @version $Rev$ $Date$
+ * Proxies getType(), write(), read() methods to appropriate TypeHelper implementation.
+ */
+public class TypeHelpersProxy {
+
+ /**
+ * Maps primitive types to its TypeHelper implementations
+ */
+ private static Map<Class<?>, TypeHelper> primitiveTypes = null;
+
+ /**
+ * Maps other types to its TypeHelper implementations
+ */
+ private static Map<NodeType, TypeHelper> complexTypes = null;
+
+ static {
+ // initiate type helpers
+ primitiveTypes = new HashMap<Class<?>, TypeHelper>();
+ complexTypes = new HashMap<NodeType, TypeHelper>();
+
+ primitiveTypes.put(boolean.class, new BooleanTypeHelper());
+ primitiveTypes.put(char.class, new CharTypeHelper());
+ primitiveTypes.put(byte.class, new ByteTypeHelper());
+ primitiveTypes.put(short.class, new ShortTypeHelper());
+ primitiveTypes.put(int.class, new IntTypeHelper());
+ primitiveTypes.put(long.class, new LongTypeHelper());
+ primitiveTypes.put(float.class, new FloatTypeHelper());
+ primitiveTypes.put(double.class, new DoubleTypeHelper());
+ primitiveTypes.put(String.class, new StringTypeHelper());
+ primitiveTypes.put(Boolean.class, primitiveTypes.get(boolean.class));
+ primitiveTypes.put(Character.class, primitiveTypes.get(char.class));
+ primitiveTypes.put(Byte.class, primitiveTypes.get(byte.class));
+ primitiveTypes.put(Short.class, primitiveTypes.get(short.class));
+ primitiveTypes.put(Integer.class, primitiveTypes.get(int.class));
+ primitiveTypes.put(Long.class, primitiveTypes.get(long.class));
+ primitiveTypes.put(Float.class, primitiveTypes.get(float.class));
+ primitiveTypes.put(Double.class, primitiveTypes.get(double.class));
+ primitiveTypes.put(String.class, primitiveTypes.get(String.class));
+ complexTypes.put(NodeType.array, new ArrayTypeHelper());
+ complexTypes.put(NodeType.struct, new StructTypeHelper());
+ complexTypes.put(NodeType.reference, new ReferenceTypeHelper());
+ complexTypes.put(NodeType.sequence, new SequenceTypeHelper());
+ }
+
+ /**
+ * Gets type helper basing on given type
+ *
+ * @param node
+ * @return
+ */
+ private static TypeHelper getTypeHelper(TypeTreeNode node) {
+ TypeHelper typeHelper = null;
+ NodeType type = node.getNodeType();
+ if (type.equals(NodeType.primitive)) {
+ typeHelper = primitiveTypes.get(node.getJavaClass());
+ } else {
+ typeHelper = complexTypes.get(type);
+ }
+ return typeHelper;
+ }
+
+ /**
+ * Proxies getType method invocation to appropriate TypeHelper
+ * implementation. It's not being used since I've changed method for passing
+ * arguments. May be useful while implementing CORBA service bindings.
+ *
+ * @param node
+ * @return
+ */
+ public static final TypeCode getType(TypeTreeNode node) {
+ TypeHelper typeHelper = getTypeHelper(node);
+ TypeCode typeCode = typeHelper.getType(node);
+ return typeCode;
+ }
+
+ /**
+ * Proxies read method invocation to appropriate TypeHelper implementation.
+ *
+ * @param node
+ * @param is
+ * @return
+ */
+ public static final Object read(TypeTreeNode node, InputStream is) {
+ TypeHelper helper = getTypeHelper(node);
+ return helper.read(node, is);
+ }
+
+ /**
+ * Proxies write method invocation to appropriate TypeHelper implementation.
+ *
+ * @param node
+ * @param os
+ * @param data
+ */
+ public static final void write(TypeTreeNode node, OutputStream os,
+ Object data) {
+ TypeHelper helper = getTypeHelper(node);
+ helper.write(node, os, data);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelpersProxy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/util/TypeHelpersProxy.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory?rev=668328&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory (added)
+++ incubator/tuscany/java/sca/modules/binding-corba-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory Mon Jun 16 14:58:09 2008
@@ -0,0 +1,19 @@
+# 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.
+
+# Implementation class for the binding extension
+org.apache.tuscany.sca.binding.corba.impl.CorbaBindingProviderFactory;model=org.apache.tuscany.sca.binding.corba.CorbaBinding