summaryrefslogtreecommitdiffstats
path: root/branches/sca-android/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHelper.java
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-09-15 06:50:04 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-09-15 06:50:04 +0000
commit147ed48e86bb4a13e42df35f1d1d800a7b564f4b (patch)
tree2412db1dcc7b46a214d2b7b46d21349ac08aa9b8 /branches/sca-android/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHelper.java
parent512771c8a42d2cde253f6df55ef552f7a0b4f792 (diff)
Removed more modules as in Oscar's TUSCANY-2440 reduced-set patch. Also removed newer modules added since r643746 and are not required to run the minimum set that we are porting to android. Set svn ignore properties to ignore Manifest files produced by the build.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@695356 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-android/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHelper.java')
-rw-r--r--branches/sca-android/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHelper.java166
1 files changed, 0 insertions, 166 deletions
diff --git a/branches/sca-android/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHelper.java b/branches/sca-android/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHelper.java
deleted file mode 100644
index 5f90aa4d7a..0000000000
--- a/branches/sca-android/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHelper.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * 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.databinding.jaxb;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-/**
- * The JAXBWrapper tool is used to create a JAXB Object from a series of child objects (wrap) or get
- * the child objects from a JAXB Object (unwrap)
- */
-public class JAXBWrapperHelper {
-
- /**
- * unwrap Returns the list of child objects of the jaxb object
- *
- * @param jaxbObject that represents the type
- * @param childNames list of xml child names as String
- * @param pdMap PropertyDescriptor map for this jaxbObject
- * @return list of Objects in the same order as the element names.
- */
- public Object[] unwrap(Object jaxbObject, List<String> childNames, Map<String, JAXBPropertyDescriptor> pdMap)
- throws JAXBWrapperException {
-
- // Get the object that will have the property descriptors (i.e. the object representing the complexType)
- Object jaxbComplexTypeObj = jaxbObject;
-
- // Get the PropertyDescriptorPlus map.
- // The method makes sure that each child name has a matching jaxb property
- // checkPropertyDescriptorMap(jaxbComplexTypeObj.getClass(), childNames, pdMap);
-
- // Get the corresponsing objects from the jaxb bean
- ArrayList<Object> objList = new ArrayList<Object>();
- int index = 0;
- for (String childName : childNames) {
- JAXBPropertyDescriptor propInfo = getPropertyDescriptor(pdMap, childName, index);
-
- Object object = null;
- try {
- object = propInfo.get(jaxbComplexTypeObj);
- } catch (Throwable e) {
- throw new JAXBWrapperException(e);
- }
-
- objList.add(object);
- index++;
- }
- Object[] jaxbObjects = objList.toArray();
- objList = null;
- return jaxbObjects;
-
- }
-
- private JAXBPropertyDescriptor getPropertyDescriptor(Map<String, JAXBPropertyDescriptor> pdMap,
- String childName,
- int index) {
- JAXBPropertyDescriptor propInfo = pdMap.get(childName);
- if (propInfo == null) {
- // FIXME: [rfeng] Sometimes the child element names don't match. Get chilld by location?
- List<JAXBPropertyDescriptor> props = new ArrayList<JAXBPropertyDescriptor>(pdMap.values());
- // Sort the properties by index. We might need to take propOrder into consideration
- Collections.sort(props);
- propInfo = props.get(index);
- }
- return propInfo;
- }
-
- /**
- * wrap Creates a jaxb object that is initialized with the child objects.
- * <p/>
- * Note that the jaxbClass must be the class the represents the complexType. (It should never be
- * JAXBElement)
- *
- * @param jaxbClass
- * @param childNames list of xml child names as String
- * @param childObjects, component type objects
- * @param pdMap PropertyDescriptor map for this jaxbObject
- */
- public Object wrap(Class<?> jaxbClass,
- List<String> childNames,
- Map<String, Object> childObjects,
- Map<String, JAXBPropertyDescriptor> pdMap) throws JAXBWrapperException {
-
- // Just like unWrap, get the property info map
- // checkPropertyDescriptorMap(jaxbClass, childNames, pdMap);
-
- // The jaxb object always has a default constructor. Create the object
- Object jaxbObject = null;
- try {
- jaxbObject = jaxbClass.newInstance();
- } catch (Throwable t) {
- throw new JAXBWrapperException(t);
- }
-
- wrap(jaxbObject, childNames, childObjects, pdMap);
-
- // Return the jaxb object
- return jaxbObject;
- }
-
- public void wrap(Object jaxbObject,
- List<String> childNames,
- Map<String, Object> childObjects,
- Map<String, JAXBPropertyDescriptor> pdMap) {
- // Now set each object onto the jaxb object
- int index = 0;
- for (String childName : childNames) {
- JAXBPropertyDescriptor propInfo = getPropertyDescriptor(pdMap, childName, index);
- Object value = childObjects.get(childName);
- try {
- propInfo.set(jaxbObject, value);
- } catch (Throwable t) {
- throw new JAXBWrapperException(t);
- }
- index++;
- }
- }
-
- public Object[] unwrap(Object jaxbObject, List<String> childNames) throws JAXBWrapperException {
- // Get the property descriptor map for this JAXBClass
- Class<?> jaxbClass = jaxbObject.getClass();
- Map<String, JAXBPropertyDescriptor> pdMap = null;
- try {
- pdMap = XMLRootElementUtil.createPropertyDescriptorMap(jaxbClass);
- } catch (Throwable t) {
- throw new JAXBWrapperException(t);
- }
-
- // Delegate
- return unwrap(jaxbObject, childNames, pdMap);
- }
-
- public Object wrap(Class<?> jaxbClass, List<String> childNames, Map<String, Object> childObjects)
- throws JAXBWrapperException {
- // Get the property descriptor map
- Map<String, JAXBPropertyDescriptor> pdMap = null;
- try {
- pdMap = XMLRootElementUtil.createPropertyDescriptorMap(jaxbClass);
- } catch (Throwable t) {
- throw new JAXBWrapperException(t);
- }
-
- // Delegate
- return wrap(jaxbClass, childNames, childObjects, pdMap);
- }
-
-}