diff options
Diffstat (limited to 'tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper')
9 files changed, 0 insertions, 1421 deletions
diff --git a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/CopyHelperImpl.java b/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/CopyHelperImpl.java deleted file mode 100644 index 060bd381dc..0000000000 --- a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/CopyHelperImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * - * 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.tuscany.sdo.helper; - - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.ecore.util.EcoreUtil.Copier; - -import commonj.sdo.DataObject; -import commonj.sdo.helper.CopyHelper; - - -/** - * A helper for copying DataObjects. - */ -public class CopyHelperImpl implements CopyHelper -{ - public DataObject copyShallow(DataObject dataObject) - { - Copier copier = new Copier() - { - protected void copyContainment(EReference eReference, EObject eObject, EObject copyEObject) - { - } - }; - EObject result = copier.copy((EObject)dataObject); - copier.copyReferences(); - return (DataObject)result; - } - - public DataObject copy(DataObject dataObject) - { - return (DataObject)EcoreUtil.copy((EObject)dataObject); - } -} diff --git a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DataFactoryImpl.java b/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DataFactoryImpl.java deleted file mode 100644 index 5fcf3fa4c1..0000000000 --- a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DataFactoryImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * - * 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.tuscany.sdo.helper; - -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.util.EcoreUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.Type; -import commonj.sdo.helper.DataFactory; -import commonj.sdo.helper.TypeHelper; - -/** - * A Factory for creating DataObjects. - * The created DataObjects are not connected to any other DataObjects. - */ -public class DataFactoryImpl implements DataFactory -{ - protected TypeHelper typeHelper; - - public DataFactoryImpl(TypeHelper typeHelper) - { - this.typeHelper = typeHelper; - } - - public DataObject create(String uri, String typeName) - { - Type type = typeHelper.getType(uri, typeName); - return create(type); - } - - public DataObject create(Class interfaceClass) - { - //TODO more efficient implementation ... this is a really bad one! - Type type = typeHelper.getType(interfaceClass); - return create(type); - } - - public DataObject create(Type type) - { - EClass eClass = (EClass)type; - return (DataObject)EcoreUtil.create(eClass); - } -} diff --git a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DataHelperImpl.java b/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DataHelperImpl.java deleted file mode 100644 index 3986fa4be7..0000000000 --- a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DataHelperImpl.java +++ /dev/null @@ -1,303 +0,0 @@ -/** - * - * 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.tuscany.sdo.helper; - -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Locale; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; - - -import commonj.sdo.helper.DataHelper; - -/** - * Data helper methods. - */ -public class DataHelperImpl implements DataHelper -{ - /** - * @param dateString - Must comply to the pattern of yyyy-MM-dd'T'HH:mm:ss'.'SSS Z - * @return null if dataString couldn't be parsed - */ - public synchronized Date toDate(String dateString) - { - if (dateString == null) - { - return null; - } - - DateFormat [] DATE_PATTERNS = - { - new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSS Z"), - new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSS"), - new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"), - new SimpleDateFormat("yyyy-MM-dd'T'HH:mm"), - new SimpleDateFormat("yyyy-MM-dd") - }; - - for (int i = 0; i < DATE_PATTERNS.length; ++i) - { - try - { - return DATE_PATTERNS[i].parse(dateString); - } - catch (ParseException parseException) - { - } - } - - return null; - } - - public synchronized Calendar toCalendar(String dateString) - { - if (dateString == null) - { - return null; - } - - Date date = toDate(dateString); - if (date == null) - { - return null; - } - - Calendar calendar = new GregorianCalendar(); - calendar.setTime(date); - - return calendar; - } - - public synchronized Calendar toCalendar(String dateString, Locale locale) - { - if (dateString == null || locale == null) - { - return null; - } - - Date date = toDate(dateString); - if (date == null) - { - return null; - } - - Calendar calendar = new GregorianCalendar(locale); - calendar.setTime(date); - return calendar; - } - - public synchronized String toDateTime(Date date) - { - if (date == null) - { - return null; - } - - SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSS zz"); - - return f.format(date); - } - - public synchronized String toDuration(Date date) - { - if (date == null) - { - return null; - } - - SimpleDateFormat f = new SimpleDateFormat("'P'yyyy'Y' MM'M' dd'D' 'T' HH'H' mm'M' ss'S.'SSS"); - - return f.format(date); - } - - public synchronized String toTime(Date date) - { - if (date == null) - { - return null; - } - - SimpleDateFormat f = new SimpleDateFormat("HH:mm:ss'.'SSS zz"); - - return f.format(date); - } - - public synchronized String toDay(Date date) - { - if (date == null) - { - return null; - } - - SimpleDateFormat f = new SimpleDateFormat("---dd zz"); - - return f.format(date); - } - - public synchronized String toMonth(Date date) - { - if (date == null) - { - return null; - } - - SimpleDateFormat f = new SimpleDateFormat("--MM zz"); - - return f.format(date); - } - - public synchronized String toMonthDay(Date date) - { - if (date == null) - { - return null; - } - - SimpleDateFormat f = new SimpleDateFormat("--MM-dd zz"); - - return f.format(date); - } - - public synchronized String toYear(Date date) - { - if (date == null) - { - return null; - } - - SimpleDateFormat f = new SimpleDateFormat("yyyy zz"); - - return f.format(date); - } - - public synchronized String toYearMonth(Date date) - { - if (date == null) - { - return null; - } - - SimpleDateFormat f = new SimpleDateFormat("yyyy-MM zz"); - - return f.format(date); - } - - public synchronized String toYearMonthDay(Date date) - { - if (date == null) - { - return null; - } - - SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd zz"); - - return f.format(date); - } - - public synchronized String toDateTime(Calendar calendar) - { - if (calendar == null) - { - return null; - } - - return toDateTime(calendar.getTime()); - } - - public synchronized String toDuration(Calendar calendar) - { - if (calendar == null) - { - return null; - } - - return toDuration(calendar.getTime()); - } - - public synchronized String toTime(Calendar calendar) - { - if (calendar == null) - { - return null; - } - - return toTime(calendar.getTime()); - } - - public synchronized String toDay(Calendar calendar) - { - if (calendar == null) - { - return null; - } - - return toDay(calendar.getTime()); - } - - public synchronized String toMonth(Calendar calendar) - { - if (calendar == null) - { - return null; - } - - return toMonth(calendar.getTime()); - } - - public synchronized String toMonthDay(Calendar calendar) - { - if (calendar == null) - { - return null; - } - - return toMonthDay(calendar.getTime()); - } - - public synchronized String toYear(Calendar calendar) - { - if (calendar == null) - { - return null; - } - - return toYear(calendar.getTime()); - } - - public synchronized String toYearMonth(Calendar calendar) - { - if (calendar == null) - { - return null; - } - - return toYearMonth(calendar.getTime()); - } - - public synchronized String toYearMonthDay(Calendar calendar) - { - if (calendar == null) - { - return null; - } - - return toYearMonthDay(calendar.getTime()); - } -} diff --git a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/EqualityHelperImpl.java b/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/EqualityHelperImpl.java deleted file mode 100644 index a31066d598..0000000000 --- a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/EqualityHelperImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * - * 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.tuscany.sdo.helper; - - -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.util.EcoreUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.helper.EqualityHelper; - - -/** - * A helper for comparing DataObjects. - */ -public class EqualityHelperImpl implements EqualityHelper -{ - public boolean equalShallow(DataObject dataObject1, DataObject dataObject2) - { - EcoreUtil.EqualityHelper equalityHelper = new EcoreUtil.EqualityHelper() - { - protected boolean haveEqualFeature(EObject eObject1, EObject eObject2, EStructuralFeature feature) - { - if (feature instanceof EAttribute) - { - boolean eIsSet = eObject1.eIsSet(feature); - if (eIsSet != eObject2.eIsSet(feature) || !haveEqualAttribute(eObject1, eObject2, (EAttribute)feature)) - { - return false; - } - } - return true; - } - - protected boolean equalFeatureMapValues(Object value1, Object value2, EStructuralFeature feature) - { - if (feature instanceof EAttribute) - { - return value1 == null ? value2 == null : value1.equals(value2); - } - return true; - } - }; - return equalityHelper.equals((EObject)dataObject1, (EObject)dataObject2); - } - - public boolean equal(DataObject dataObject1, DataObject dataObject2) - { - return EcoreUtil.equals((EObject)dataObject1, (EObject)dataObject2); - } -} diff --git a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java b/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java deleted file mode 100644 index d0ece134e3..0000000000 --- a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * - * 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.tuscany.sdo.helper; - - -import org.apache.tuscany.sdo.helper.CopyHelperImpl; -import org.apache.tuscany.sdo.helper.DataHelperImpl; -import org.apache.tuscany.sdo.helper.EqualityHelperImpl; -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.helper.CopyHelper; -import commonj.sdo.helper.DataFactory; -import commonj.sdo.helper.DataHelper; -import commonj.sdo.helper.EqualityHelper; -import commonj.sdo.helper.TypeHelper; -import commonj.sdo.helper.XMLHelper; -import commonj.sdo.helper.XSDHelper; -import commonj.sdo.impl.ExternalizableDelegator.Resolvable; -import commonj.sdo.impl.HelperProvider; - - -/** - * Create and manage all the default helper INSTANCEs - */ -public class HelperProviderImpl extends HelperProvider -{ - protected CopyHelper copyHelper; - - protected DataFactory dataFactory; - - protected DataHelper dataHelper; - - protected EqualityHelper equalityHelper; - - protected TypeHelper typeHelper; - - protected XMLHelper xmlHelper; - - protected XSDHelper xsdHelper; - - public HelperProviderImpl() - { - typeHelper = SDOUtil.createTypeHelper(); - dataFactory = SDOUtil.createDataFactory(typeHelper); - xmlHelper = SDOUtil.createXMLHelper(typeHelper); - xsdHelper = SDOUtil.createXSDHelper(typeHelper); - copyHelper = new CopyHelperImpl(); - equalityHelper = new EqualityHelperImpl(); - dataHelper = new DataHelperImpl(); - } - - public CopyHelper copyHelper() - { - return copyHelper; - } - - public DataFactory dataFactory() - { - return dataFactory; - } - - public DataHelper dataHelper() - { - return dataHelper; - } - - public EqualityHelper equalityHelper() - { - return equalityHelper; - } - - public TypeHelper typeHelper() - { - return typeHelper; - } - - public XMLHelper xmlHelper() - { - return xmlHelper; - } - - public XSDHelper xsdHelper() - { - return xsdHelper; - } - - public Resolvable resolvable() - { - throw new UnsupportedOperationException(); //TODO - } - - public Resolvable resolvable(Object target) - { - throw new UnsupportedOperationException(); //TODO - } -} diff --git a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/TypeHelperImpl.java b/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/TypeHelperImpl.java deleted file mode 100644 index 38c4c962e7..0000000000 --- a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/TypeHelperImpl.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * - * 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.tuscany.sdo.helper; - - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.emf.ecore.EClassifier; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.util.ExtendedMetaData; - -import commonj.sdo.DataObject; -import commonj.sdo.Type; -import commonj.sdo.helper.TypeHelper; - - -/** - * Look up a Type given the uri and typeName or interfaceClass. - * SDO Types are available through the - * getType("commonj.sdo", typeName) method. - * Defines Types from DataObjects. - */ -public class TypeHelperImpl implements TypeHelper -{ - protected ExtendedMetaData extendedMetaData; - - public TypeHelperImpl(ExtendedMetaData extendedMetaData) - { - this.extendedMetaData = extendedMetaData; - } - - public Type getType(String uri, String typeName) - { - EPackage ePackage = extendedMetaData.getPackage(uri); - if (ePackage != null) - { - EClassifier eClassifier = ePackage.getEClassifier(typeName); - if (eClassifier == null) - { - eClassifier = extendedMetaData.getType(ePackage, typeName); - } - return (Type)eClassifier; - } - return null; - } - - public Type getType(Class interfaceClass) - { - //TODO more efficient implementation ... this is a really bad one! - for (Iterator iter = EPackage.Registry.INSTANCE.values().iterator(); iter.hasNext(); ) - { - Object value = iter.next(); - if (value instanceof EPackage) - { - EPackage ePackage = (EPackage)value; - for (Iterator iter2 = ePackage.getEClassifiers().iterator(); iter2.hasNext(); ) - { - EClassifier eClassifier = (EClassifier)iter2.next(); - if (eClassifier.getInstanceClass() == interfaceClass) - { - return (Type)eClassifier; - } - } - } - } - return null; - } - - public Type define(DataObject type) - { - throw new UnsupportedOperationException(); //TODO - } - - public List /*Type*/define(List /*DataObject*/types) - { - throw new UnsupportedOperationException(); //TODO - } - -} diff --git a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XMLDocumentImpl.java b/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XMLDocumentImpl.java deleted file mode 100644 index 2626eb12ff..0000000000 --- a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XMLDocumentImpl.java +++ /dev/null @@ -1,349 +0,0 @@ -/** - * - * 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.tuscany.sdo.helper; - - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.sdo.SDOPackage; -import org.apache.tuscany.sdo.util.DataObjectUtil; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.ecore.util.ExtendedMetaData; -import org.eclipse.emf.ecore.xmi.XMLOptions; -import org.eclipse.emf.ecore.xmi.XMLParserPool; -import org.eclipse.emf.ecore.xmi.XMLResource; -import org.eclipse.emf.ecore.xmi.impl.XMLOptionsImpl; -import org.eclipse.emf.ecore.xmi.impl.XMLParserPoolImpl; -import org.xml.sax.InputSource; - -import commonj.sdo.DataObject; -import commonj.sdo.helper.XMLDocument; - - -/** - * Represents an XML Document containing a tree of DataObjects. - * - * An example XMLDocument fragment is: - * <?xml version="1.0"?> - * <purchaseOrder orderDate="1999-10-20"> - * - * created from this XML Schema fragment: - * <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> - * <xsd:element name="purchaseOrder" type="PurchaseOrderType"/> - * <xsd:complexType name="PurchaseOrderType"> - * - * Upon loading this XMLDocument: - * DataObject is an instance of Type PurchaseOrderType. - * RootElementURI is null because the XSD has no targetNamespace URI. - * RootElementName is purchaseOrder. - * Encoding is null because the document did not specify an encoding. - * XMLDeclaration is true because the document contained an XML declaration. - * XMLVersion is 1.0 - * SchemaLocation and noNamespaceSchemaLocation are null because they are - * not specified in the document. - * - * When saving the root element, if the type of the root dataObject is not the - * type of global element specified by rootElementURI and rootElementName, - * or if a global element does not exist for rootElementURI and rootElementName, - * then an xsi:type declaration is written to record the root DataObject's Type. - * - * When loading the root element and an xsi:type declaration is found - * it is used as the type of the root DataObject. In this case, - * if validation is not being performed, it is not an error if the - * rootElementName is not a global element. - */ -public class XMLDocumentImpl implements XMLDocument -{ - protected ExtendedMetaData extendedMetaData; - - protected EObject rootObject; - - protected XMLResource resource; - - protected EStructuralFeature rootElement; - - protected EObject documentRoot; - - protected static XMLParserPool globalXMLParserPool = new XMLParserPoolImpl(); - - //TODO clean up the options thing - protected XMLDocumentImpl(ExtendedMetaData extendedMetaData, Object options) - { - this.extendedMetaData = extendedMetaData; - ResourceSet resourceSet = DataObjectUtil.createResourceSet(); - - if (options instanceof Map) - { - Class resourceFactoryClass = (Class)((Map)options).get("GENERATED_LOADER"); - if (resourceFactoryClass != null) - { - try - { - Object resourceFactory = resourceFactoryClass.newInstance(); - resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", resourceFactory); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - } - - resource = (XMLResource)resourceSet.createResource(URI.createURI("http:///temp.xml")); - - XMLOptions xmlOptions = new XMLOptionsImpl(); - xmlOptions.setProcessAnyXML(true); - resource.getDefaultLoadOptions().put(XMLResource.OPTION_XML_OPTIONS, xmlOptions); - - resource.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData); - resource.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData); - - resource.getDefaultLoadOptions().put(XMLResource.OPTION_USE_PARSER_POOL, globalXMLParserPool); - - resource.getDefaultLoadOptions().put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.FALSE); - - resource.getDefaultSaveOptions().put(XMLResource.OPTION_CONFIGURATION_CACHE, Boolean.TRUE); - resource.getDefaultLoadOptions().put(XMLResource.OPTION_CONFIGURATION_CACHE, Boolean.TRUE); - - resource.getDefaultLoadOptions().put(XMLResource.OPTION_ANY_TYPE, SDOPackage.eINSTANCE.getAnyTypeDataObject()); - resource.getDefaultSaveOptions().put(XMLResource.OPTION_ANY_TYPE, SDOPackage.eINSTANCE.getAnyTypeDataObject()); - - resource.getDefaultLoadOptions().put(XMLResource.OPTION_ANY_SIMPLE_TYPE, SDOPackage.eINSTANCE.getSimpleAnyTypeDataObject()); - resource.getDefaultSaveOptions().put(XMLResource.OPTION_ANY_SIMPLE_TYPE, SDOPackage.eINSTANCE.getSimpleAnyTypeDataObject()); - - //resource.getDefaultLoadOptions().put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP, globalHashMap); - - //resource.getDefaultSaveOptions().put(XMLResource.OPTION_FORMATTED, Boolean.FALSE); - } - - protected XMLDocumentImpl(ExtendedMetaData extendedMetaData) - { - this(extendedMetaData, null); - } - - protected XMLDocumentImpl(ExtendedMetaData extendedMetaData, DataObject dataObject, String rootElementURI, String rootElementName) - { - this(extendedMetaData); - - rootObject = (EObject)dataObject; - - rootElement = extendedMetaData.getElement(rootElementURI, rootElementName); - if (rootElement == null) - { - rootElement = ExtendedMetaData.INSTANCE.demandFeature(rootElementURI, rootElementName, true); - } - - EClass documentRootClass = rootElement.getEContainingClass(); - documentRoot = EcoreUtil.create(documentRootClass); - resource.getContents().add(documentRoot); - } - - protected void save(OutputStream outputStream, Object options) throws IOException - { - EObject oldContainer = null; - EReference oldContainmentReference = null; - int oldContainmentIndex = -1; - - if (documentRoot != null) - { - //TODO also check if rootObject is directly contained in a resource - oldContainer = rootObject.eContainer(); - if (oldContainer != null) - { - oldContainmentReference = rootObject.eContainmentFeature(); - } - if (oldContainer != documentRoot || oldContainmentReference != rootElement) - { - if (oldContainmentReference != null && oldContainmentReference.isMany()) - { - oldContainmentIndex = ((List)oldContainer.eGet(oldContainmentReference)).indexOf(rootObject); - } - documentRoot.eSet(rootElement, rootObject); - } - } - - resource.save(outputStream, (Map)options); - - if (oldContainer != null) - { - if (oldContainer != documentRoot || oldContainmentReference != rootElement) - { - if (oldContainmentReference.isMany()) - { - ((List)oldContainer.eGet(oldContainmentReference)).add(oldContainmentIndex, rootObject); - } - else - { - oldContainer.eSet(oldContainmentReference, rootObject); - } - } - } - else if (documentRoot != null) - { - documentRoot.eSet(rootElement, null); - } - } - - protected void save(Writer outputWriter, Object options) throws IOException - { - // TODO temporary brute-force implementation ... to be replaced - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - save(outputStream, options); - outputWriter.write(new String(outputStream.toByteArray())); - } - - protected void load(InputStream inputStream, String locationURI, Object options) throws IOException - { - InputSource inputSource = new InputSource(inputStream); - load(inputSource, locationURI, options); - } - - protected void load(Reader inputReader, String locationURI, Object options) throws IOException - { - InputSource inputSource = new InputSource(inputReader); - load(inputSource, locationURI, options); - } - - protected void load(InputSource inputSource, String locationURI, Object options) throws IOException - { - rootObject = null; - rootElement = null; - documentRoot = null; - - if (locationURI != null) - { - inputSource.setSystemId(locationURI); - resource.setURI(URI.createURI(locationURI)); - } - - resource.load(inputSource, (Map)options); - - if (!resource.getContents().isEmpty()) - { - documentRoot = (EObject)resource.getContents().get(0); - EClass documentRootClass = documentRoot.eClass(); - if ("".equals(extendedMetaData.getName(documentRootClass))) //TODO efficient way to check this? Maybe DataObject.getContainer should also check this? - { - if (!documentRoot.eContents().isEmpty()) - { - rootObject = (EObject)documentRoot.eContents().get(0); - rootElement = rootObject.eContainmentFeature(); - documentRoot.eUnset(rootElement); - } - } - else - { - rootObject = documentRoot; - documentRoot = null; - } - } - } - - public DataObject getRootObject() - { - return (DataObject)rootObject; - } - - public String getRootElementURI() - { - if (rootElement != null) - { - return extendedMetaData.getNamespace(rootElement); - } - else if (rootObject != null) - { - return extendedMetaData.getNamespace(rootObject.eClass()); - } - return null; - } - - public String getRootElementName() - { - if (rootElement != null) - { - return extendedMetaData.getName(rootElement); - } - else if (rootObject != null) - { - return extendedMetaData.getName(rootObject.eClass()); - } - return null; - } - - public String getEncoding() - { - return resource.getEncoding(); - } - - public void setEncoding(String encoding) - { - resource.setEncoding(encoding); - } - - public boolean isXMLDeclaration() - { - return Boolean.FALSE.equals(resource.getDefaultSaveOptions().get(XMLResource.OPTION_DECLARE_XML)); - } - - public void setXMLDeclaration(boolean xmlDeclaration) - { - resource.getDefaultSaveOptions().put(XMLResource.OPTION_DECLARE_XML, xmlDeclaration ? Boolean.TRUE : Boolean.FALSE); - } - - public String getXMLVersion() - { - return "1.0"; //TODO - } - - public void setXMLVersion(String xmlVersion) - { - throw new UnsupportedOperationException(); //TODO - } - - public String getSchemaLocation() - { - throw new UnsupportedOperationException(); //TODO - } - - public void setSchemaLocation(String schemaLocation) - { - throw new UnsupportedOperationException(); //TODO - } - - public String getNoNamespaceSchemaLocation() - { - throw new UnsupportedOperationException(); //TODO - } - - public void setNoNamespaceSchemaLocation(String schemaLocation) - { - throw new UnsupportedOperationException(); //TODO - } -} diff --git a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XMLHelperImpl.java b/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XMLHelperImpl.java deleted file mode 100644 index 653665e1b8..0000000000 --- a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XMLHelperImpl.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * - * 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.tuscany.sdo.helper; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; - -import org.eclipse.emf.ecore.util.ExtendedMetaData; - -import commonj.sdo.DataObject; -import commonj.sdo.helper.TypeHelper; -import commonj.sdo.helper.XMLDocument; -import commonj.sdo.helper.XMLHelper; - -/** - * A helper to convert XML documents into DataObects and - * DataObjects into XML documnets. - */ -public class XMLHelperImpl implements XMLHelper -{ - ExtendedMetaData extendedMetaData; - - public XMLHelperImpl(ExtendedMetaData extendedMetaData) - { - this.extendedMetaData = extendedMetaData; - } - - public XMLHelperImpl(TypeHelper typeHelper) - { - this.extendedMetaData = ((TypeHelperImpl)typeHelper).extendedMetaData; - } - - public XMLDocument load(String inputString) - { - try - { - return load(new StringReader(inputString), null, null); - } - catch (IOException e) - { - throw new RuntimeException(e); // should never happen - } - } - - public XMLDocument load(InputStream inputStream) throws IOException - { - return load(inputStream, null, null); - } - - public XMLDocument load(InputStream inputStream, String locationURI, Object options) throws IOException - { - XMLDocumentImpl document = new XMLDocumentImpl(extendedMetaData, options); - document.load(inputStream, locationURI, options); - return document; - } - - public XMLDocument load(Reader inputReader, String locationURI, Object options) throws IOException - { - XMLDocumentImpl document = new XMLDocumentImpl(extendedMetaData, options); - document.load(inputReader, locationURI, options); - return document; - } - - public String save(DataObject dataObject, String rootElementURI, String rootElementName) - { - StringWriter stringWriter = new StringWriter(); - try - { - save(createDocument(dataObject, rootElementURI, rootElementName), stringWriter, null); - return stringWriter.toString(); - } - catch (IOException e) - { - throw new RuntimeException(e); // should never happen - } - } - - public void save(DataObject dataObject, String rootElementURI, String rootElementName, OutputStream outputStream) throws IOException - { - save(createDocument(dataObject, rootElementURI, rootElementName), outputStream, null); - } - - public void save(XMLDocument xmlDocument, OutputStream outputStream, Object options) throws IOException - { - ((XMLDocumentImpl)xmlDocument).save(outputStream, options); - } - - public void save(XMLDocument xmlDocument, Writer outputWriter, Object options) throws IOException - { - ((XMLDocumentImpl)xmlDocument).save(outputWriter, options); - } - - public XMLDocument createDocument(DataObject dataObject, String rootElementURI, String rootElementName) - { - return new XMLDocumentImpl(extendedMetaData, dataObject, rootElementURI, rootElementName); - } -} diff --git a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XSDHelperImpl.java b/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XSDHelperImpl.java deleted file mode 100644 index 3173601861..0000000000 --- a/tags/java-stable-20060304/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XSDHelperImpl.java +++ /dev/null @@ -1,273 +0,0 @@ -/** - * - * 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.tuscany.sdo.helper; - - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.io.Reader; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.tuscany.sdo.impl.DynamicDataObjectImpl; -import org.apache.tuscany.sdo.util.DataObjectUtil; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EClassifier; -import org.eclipse.emf.ecore.EModelElement; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.EcorePackage; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.ecore.util.ExtendedMetaData; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDTypeDefinition; -import org.eclipse.xsd.ecore.XSDEcoreBuilder; -import org.eclipse.xsd.util.XSDResourceImpl; -import org.w3c.dom.Element; -import org.xml.sax.InputSource; - -import commonj.sdo.Property; -import commonj.sdo.Type; -import commonj.sdo.helper.TypeHelper; -import commonj.sdo.helper.XSDHelper; - - -/** - * Provides access to additional information when the - * Type or Property is defined by an XML Schema (XSD). - * Methods return null/false otherwise or if the information is unavailable. - * Defines Types from an XSD. - */ -public class XSDHelperImpl implements XSDHelper -{ - private XSDEcoreBuilder ecoreBuilder; - - private ExtendedMetaData extendedMetaData; - - public XSDHelperImpl(ExtendedMetaData extendedMetaData) - { - this.extendedMetaData = extendedMetaData; - ecoreBuilder = new SDOXSDEcoreBuilder(extendedMetaData); - } - - public XSDHelperImpl(TypeHelper typeHelper) - { - this(((TypeHelperImpl)typeHelper).extendedMetaData); - } - - public String getLocalName(Type type) - { - return extendedMetaData.getName((EClassifier)type); - } - - public String getLocalName(Property property) - { - return extendedMetaData.getName((EStructuralFeature)property); - } - - public String getNamespaceURI(Property property) - { - return extendedMetaData.getNamespace((EStructuralFeature)property); - } - - public boolean isAttribute(Property property) - { - return extendedMetaData.getFeatureKind((EStructuralFeature)property) == ExtendedMetaData.ATTRIBUTE_FEATURE; - } - - public boolean isElement(Property property) - { - return extendedMetaData.getFeatureKind((EStructuralFeature)property) == ExtendedMetaData.ELEMENT_FEATURE; - } - - public boolean isMixed(Type type) - { - if (type instanceof EClass) - { - return extendedMetaData.getContentKind((EClass)type) == ExtendedMetaData.MIXED_CONTENT; - } - else - { - return false; - } - } - - public boolean isXSD(Type type) - { - return ((EModelElement)type).getEAnnotation(ExtendedMetaData.ANNOTATION_URI) != null; - } - - public Property getGlobalProperty(String uri, String propertyName, boolean isElement) - { - if (isElement) - { - return (Property)extendedMetaData.getElement(uri, propertyName); - } - else - { - return (Property)extendedMetaData.getAttribute(uri, propertyName); - } - } - - public String getAppinfo(Type type, String source) - { - return getAppinfo((EModelElement)type, source); - } - - public String getAppinfo(Property property, String source) - { - return getAppinfo((EModelElement)property, source); - } - - protected String getAppinfo(EModelElement eModelElement, String source) - { - return (String)eModelElement.getEAnnotation(source).getDetails().get("appinfo"); - } - - public List /*Type*/define(String xsd) - { - InputStream inputStream = new ByteArrayInputStream(xsd.getBytes()); - return define(inputStream, "*.xsd"); - - } - - public List /*Type*/define(Reader xsdReader, String schemaLocation) - { - - InputSource inputSource = new InputSource(xsdReader); - return define(inputSource, schemaLocation); - - } - - public List /*Type*/define(InputStream xsdInputStream, String schemaLocation) - { - InputSource inputSource = new InputSource(xsdInputStream); - return define(inputSource, schemaLocation); - } - - protected List /*Type*/define(InputSource inputSource, String schemaLocation) - { - try - { - ResourceSet resourceSet = DataObjectUtil.createResourceSet(); - Resource model = resourceSet.createResource(URI.createURI(schemaLocation != null ? schemaLocation : "null.xsd")); - ((XSDResourceImpl)model).load(inputSource, null); - XSDSchema schema = (XSDSchema)model.getContents().get(0); - - // If define() is called more than once for the same XMLSchema, return the existing defined types - //FIXME ... need to rethink this design - //if (!ecoreBuilder.getTargetNamespaceToEPackageMap().containsKey(schema.getTargetNamespace())) - // also return generated types registered via SDOUtil.registerStaticTypes() - EPackage ePackage = extendedMetaData.getPackage(schema.getTargetNamespace()); - if (ePackage == null) - { - ecoreBuilder.generate(schema); - Collection newEPackages = ecoreBuilder.getTargetNamespaceToEPackageMap().values(); - - for (Iterator iter = newEPackages.iterator(); iter.hasNext();) - { - EPackage currentPackage = (EPackage)iter.next(); - currentPackage.setEFactoryInstance(new DynamicDataObjectImpl.FactoryImpl()); - EcoreUtil.freeze(currentPackage); - } - } - ePackage = extendedMetaData.getPackage(schema.getTargetNamespace()); - return ePackage.getEClassifiers(); - } - catch (Exception e) - { - throw new IllegalArgumentException(); - } - } - - public String generate(List /*Type*/types) - { - throw new UnsupportedOperationException(); //TODO - } - - public String generate(List /*Type*/types, Map /*String, String*/namespaceToSchemaLocation) - { - throw new UnsupportedOperationException(); //TODO - } - - protected static class SDOXSDEcoreBuilder extends XSDEcoreBuilder - { - public SDOXSDEcoreBuilder(ExtendedMetaData extendedMetaData) - { - super(extendedMetaData); - } - - protected String getEcoreAttribute(Element element, String attribute) - { - String sdoAttribute = null; - - if ("name".equals(attribute)) - sdoAttribute = "name"; - else if ("opposite".equals(attribute)) - sdoAttribute = "oppositeProperty"; - else if ("mixed".equals(attribute)) - sdoAttribute = "sequence"; - - if (sdoAttribute != null) - { - return - element != null && element.hasAttributeNS("commonj.sdo/xml", sdoAttribute) ? - element.getAttributeNS("commonj.sdo/xml", sdoAttribute) : - null; - } - - if ("package".equals(attribute)) - sdoAttribute = "package"; - else if ("instanceClass".equals(attribute)) - sdoAttribute = "instanceClass"; - - if (sdoAttribute != null) - { - return - element != null && element.hasAttributeNS("commonj.sdo/java", sdoAttribute) ? - element.getAttributeNS("commonj.sdo/java", sdoAttribute) : - null; - } - - return super.getEcoreAttribute(element, attribute); - } - - protected XSDTypeDefinition getEcoreTypeQNameAttribute(XSDConcreteComponent xsdConcreteComponent, String attribute) - { - String sdoAttribute = null; - - if ("reference".equals(attribute)) sdoAttribute = "propertyType"; - - if (sdoAttribute != null) - { - Element element = xsdConcreteComponent.getElement(); - return element == null ? null : getEcoreTypeQNameAttribute(xsdConcreteComponent, element, "commonj.sdo/xml", sdoAttribute); - } - - return super.getEcoreTypeQNameAttribute(xsdConcreteComponent, attribute); - } - - } - -} |