diff options
Diffstat (limited to 'das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf')
11 files changed, 1644 insertions, 0 deletions
diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/DataTypeToADSSyntaxMapProvider.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/DataTypeToADSSyntaxMapProvider.java new file mode 100644 index 0000000000..8bd50fb4cc --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/DataTypeToADSSyntaxMapProvider.java @@ -0,0 +1,54 @@ +package org.apache.tuscany.das.ldap.schema.emf.create; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.das.ldap.constants.SyntaxOIDValues; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EcorePackage; + +public class DataTypeToADSSyntaxMapProvider +implements SyntaxOIDValues { + + EcorePackage ecorePackage = + EcorePackage.eINSTANCE; + + private static Map<EDataType, String> dataTypeToADSSyntaxOIDMap = null; + + //TODO Make this a singleton + public DataTypeToADSSyntaxMapProvider() + { + dataTypeToADSSyntaxOIDMap = new HashMap<EDataType, String>(); + create(); + } + + public Map<EDataType, String> getDataTypeToADSSyntaxMap() + { + return dataTypeToADSSyntaxOIDMap; + } + + private Map<EDataType, String> create() + { + dataTypeToADSSyntaxOIDMap.put( + ecorePackage.getEString(), + SYNTAX_STRING_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + ecorePackage.getEInt(), + SYNTAX_INTEGER_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + ecorePackage.getEIntegerObject(), + SYNTAX_INTEGER_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + ecorePackage.getEBoolean(), + SYNTAX_BOOLEAN_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + ecorePackage.getEBooleanObject(), + SYNTAX_BOOLEAN_OID_VALUE); + + return dataTypeToADSSyntaxOIDMap; + } +}
\ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EAttributeTypeCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EAttributeTypeCreator.java new file mode 100644 index 0000000000..5b8e65c221 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EAttributeTypeCreator.java @@ -0,0 +1,113 @@ +/* + * 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.das.ldap.schema.emf.create; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.create.AbstractAttributeTypeCreator; +import org.apache.tuscany.das.ldap.schema.create.SimpleTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.provide.SyntaxOIDProvider; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; + +public class EAttributeTypeCreator +extends AbstractAttributeTypeCreator +{ + public EAttributeTypeCreator() + { + super(); + } + /** + * Create. + * + * @param oidPrefix the oid prefix + * @param eAttribute the e attribute + * @param attributeTypesContext the attribute types context + * + * @throws Exception the exception + * @throws NamingException the naming exception + */ + public void create( + DirContext attributeTypesContext, + EAttribute eAttribute, + String oidPrefix) + throws NamingException, Exception + { + String eAttributeName = + eAttribute.getName(); + + EClass eContainingClass = + eAttribute.getEContainingClass(); + + String eContainingClassName = + eContainingClass.getName(); + + String namespaceURI = + eContainingClass. + getEPackage().getNsURI(); + + String qualifiedEAttributeNameURI = + SimpleTypeNamespaceQualifier.qualify( + namespaceURI, + eContainingClassName, + eAttributeName); + + String normalizedEAttributeName = + QualifiedNameNormalizer. + normalize(qualifiedEAttributeNameURI); + + EClassifier eDataType = + eAttribute.getEType(); + + SyntaxOIDProvider dataTypeToADSSyntaxMapProvider = + new SyntaxOIDProvider(); + + String syntaxOID = + dataTypeToADSSyntaxMapProvider. + getSyntaxOID(eDataType); + + basicAttributes.put( + M_DESCRIPTION, + eAttributeName); + + basicAttributes.put( + M_SYNTAX, + syntaxOID); + + basicAttributes.put( + M_NAME, + normalizedEAttributeName ); + + String rdn = + SimpleTypeRDNCreator.create( + oidPrefix, + namespaceURI, + eContainingClassName, + eAttributeName); + + attributeTypesContext.createSubcontext( + rdn, + basicAttributes); + } +}
\ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EObjectClassCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EObjectClassCreator.java new file mode 100644 index 0000000000..684509e0d9 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EObjectClassCreator.java @@ -0,0 +1,202 @@ +/* + * 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.das.ldap.schema.emf.create; + +import java.util.List; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.create.AbstractTypeCreator; +import org.apache.tuscany.das.ldap.schema.create.ComplexTypeRDNCreator; +import org.apache.tuscany.das.ldap.util.ComplexTypeNamespaceQualifier; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.eclipse.emf.ecore.EClass; + +public class EObjectClassCreator +extends AbstractTypeCreator +{ + public EObjectClassCreator() + { + super(); + } + /** + * Create. + * + * @param oidPrefix the oid prefix + * @param eAttribute the e attribute + * @param attributeTypesContext the attribute types context + * + * @throws Exception the exception + * @throws NamingException the naming exception + * + * Note that null can passed for the processedEClassifiers list + * only when the EClass has not parents. + */ + public void create( + DirContext metaContext, + DirContext attributeTypesContext, + DirContext objectClassesContext, + EClass eClass, + List<EClass> processedEClassifiers, + String oidPrefix) + throws NamingException, Exception + { + if ( processedEClassifiers != null ) + { + EClass eClassParent = + EcoreTypeSystemHelper. + getEClassParent( eClass ); + + if (eClassParent != null) + { + boolean isEClassProcessed = + EObjectClassCreatorHelper. + isEClassProcessed( + eClassParent, + processedEClassifiers); + + if (!isEClassProcessed) + { + this.create( + metaContext, + attributeTypesContext, + objectClassesContext, + eClassParent, + processedEClassifiers, + oidPrefix); + } + } + } + + objectClassAttribute.add( META_OBJECT_CLASS ); + + EcoreTypeSystemHelper. + createAttributeTypes( + attributeTypesContext, + eClass, + oidPrefix ); + + String namespaceURI = + eClass.getEPackage(). + getNsURI(); + + String qualifiedEClassNameURI = + ComplexTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName()); + + String normalizedEObjectName = + QualifiedNameNormalizer. + normalize(qualifiedEClassNameURI); + + + basicAttributes.put( + M_NAME, + normalizedEObjectName ); + + basicAttributes.put( + M_DESCRIPTION, + eClass.getName() ); + + basicAttributes.put( + M_OBSOLETE, + LDAP_FALSE ); + + //TODO Remember to test with parent combination. + EObjectClassCreatorHelper. + addParentAttribute( + basicAttributes, + namespaceURI, + eClass ); + + if (!eClass.isAbstract()) + { + basicAttributes.put( + M_TYPE_OBJECT_CLASS, + STRUCTURAL ); + } + else + { + basicAttributes.put( + M_TYPE_OBJECT_CLASS, + ABSTRACT ); + } + + + /* + EObjectClassCreatorHelper. + addEAttributes( + basicAttributes, + namespaceURI, + eClass ); + + EObjectClassCreatorHelper. + addEReferences( + basicAttributes, + namespaceURI, + eClass ); + */ + + + EObjectClassCreatorHelper. + addEStructuralFeatures( + basicAttributes, + namespaceURI, + eClass ); + + String rdn = + ComplexTypeRDNCreator. + create( + oidPrefix, + namespaceURI, + eClass.getName()); + + EObjectClassCreatorHelper. + createInheritanceMetaData( + metaContext, + eClass ); + + /* TODO - Remove once everything is simmered down + NamingEnumeration namingEnumeration = + basicAttributes.getAll(); + + while (namingEnumeration.hasMore()) + { + Attribute attribute = (Attribute) namingEnumeration.next(); + System.out.println(attribute); + } + */ + + + objectClassesContext. + createSubcontext( + rdn, + basicAttributes ); + + + if ( processedEClassifiers != null ) + { + processedEClassifiers.add(eClass); + } + } +}
\ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EObjectClassCreatorHelper.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EObjectClassCreatorHelper.java new file mode 100644 index 0000000000..2a99ef8fb8 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EObjectClassCreatorHelper.java @@ -0,0 +1,378 @@ +/* + * 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.das.ldap.schema.emf.create; + +import java.util.Iterator; +import java.util.List; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.constants.DASConstants; +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.EnumeratedSchemaAttributeTypeValues; +import org.apache.tuscany.das.ldap.schema.constants.ObjectClassConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaAttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.constants.SchemaObjectClassConstants; +import org.apache.tuscany.das.ldap.util.ComplexTypeNamespaceQualifier; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; + +/** + * The Class EObjectClassCreatorHelper. + */ +public class EObjectClassCreatorHelper +implements +EnumeratedSchemaAttributeTypeValues, +SchemaAttributeTypeConstants, +AttributeTypeConstants, +SchemaObjectClassConstants, +ObjectClassConstants, +DASConstants +{ + /** + * Adds the parent attribute. + * + * @param namespaceURI the namespace URI + * @param objectClassAttributes the object class attributes + * @param eClass the e class + */ + public static void addParentAttribute( + Attributes objectClassAttributes, + String namespaceURI, + EClass eClass) + { + EClass eClassParent = + EcoreTypeSystemHelper.getEClassParent( eClass ); + + if(eClassParent !=null) + { + String qualifiedEClassParentNameURI = + ComplexTypeNamespaceQualifier. + qualify( + namespaceURI, + eClassParent. + getName()); + + String normalizedEObjectName = + QualifiedNameNormalizer. + normalize(qualifiedEClassParentNameURI); + + objectClassAttributes.put( + M_SUP_OBJECT_CLASS, + normalizedEObjectName); + } + else + { + objectClassAttributes.put( + M_SUP_OBJECT_CLASS, + META_OBJECT_CLASS ); + } + } + + /** + * Adds the E attributes. + * + * @param namespaceURI the namespace URI + * @param objectClassAttributes the object class attributes + * @param eClass the e class + */ + public static void addEAttributes( + Attributes objectClassAttributes, + String namespaceURI, + EClass eClass) + { + List<EAttribute> eAttributes = + eClass.getEAttributes(); + + Iterator<EAttribute> eAttributeIterator = + eAttributes.iterator(); + + EAttribute eAttribute = + null; + + String qualifiedEAttributeName = + null; + + Attribute mMayAttribute = + null; + + Attribute mMustAttribute = + null; + + while( eAttributeIterator.hasNext()) + { + eAttribute = eAttributeIterator.next(); + + qualifiedEAttributeName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName(), + eAttribute.getName()); + + String normalizedEAttributeName = + QualifiedNameNormalizer. + normalize(qualifiedEAttributeName); + + if (!eAttribute.isRequired()) + { + if (mMayAttribute == null) + { + mMayAttribute = new BasicAttribute(M_MAY); + } + mMayAttribute.add(normalizedEAttributeName); + } + else + { + if (mMustAttribute == null) + { + mMustAttribute = new BasicAttribute(M_MUST); + } + mMustAttribute.add(normalizedEAttributeName); + } + } + + if (mMayAttribute != null) + { + objectClassAttributes.put( mMayAttribute ); + } + if (mMustAttribute != null) + { + objectClassAttributes.put( mMustAttribute ); + } + } + + /** + * Adds the E references. + * + * @param namespaceURI the namespace URI + * @param objectClassAttributes the object class attributes + * @param eClass the e class + */ + public static void addEReferences( + Attributes objectClassAttributes, + String namespaceURI, + EClass eClass) + { + List<EReference> eReferences = + eClass.getEReferences(); + + Iterator<EReference> eReferenceIterator = + eReferences.iterator(); + + EReference eReference = + null; + + String qualifiedEReferenceName = + null; + + Attribute mMayAttribute = + null; + + Attribute mMustAttribute = + null; + + while ( eReferenceIterator.hasNext()) + { + eReference = eReferenceIterator.next(); + + qualifiedEReferenceName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName(), + eReference.getName()); + + String normalizedEReferenceName = + QualifiedNameNormalizer. + normalize(qualifiedEReferenceName); + + if (!eReference.isRequired()) + { + if (mMayAttribute == null) + { + mMayAttribute = new BasicAttribute(M_MAY); + } + mMayAttribute.add( normalizedEReferenceName ); + } + else + { + if (mMustAttribute == null) + { + mMustAttribute = new BasicAttribute(M_MUST); + } + mMustAttribute.add( normalizedEReferenceName ); + } + } + if (mMayAttribute != null) + { + objectClassAttributes.put( mMayAttribute ); + } + if (mMustAttribute != null) + { + objectClassAttributes.put( mMustAttribute ); + } + } + + /** + * Adds the E references. + * + * @param namespaceURI the namespace URI + * @param objectClassAttributes the object class attributes + * @param eClass the e class + */ + public static void addEStructuralFeatures( + Attributes objectClassAttributes, + String namespaceURI, + EClass eClass) + { + List<EStructuralFeature> eStructuralFeatures = + eClass.getEStructuralFeatures(); + + Iterator<EStructuralFeature> eStructuralFeatureIterator = + eStructuralFeatures.iterator(); + + EStructuralFeature eStructuralFeature = + null; + + String qualifiedEStructuralFeatureName = + null; + + Attribute mMayAttribute = + null; + + Attribute mMustAttribute = + null; + + while ( eStructuralFeatureIterator.hasNext()) + { + eStructuralFeature = + eStructuralFeatureIterator.next(); + + qualifiedEStructuralFeatureName = + SimpleTypeNamespaceQualifier. + qualify( + namespaceURI, + eClass.getName(), + eStructuralFeature.getName()); + + String normalizedEStructuralFeatureName = + QualifiedNameNormalizer. + normalize(qualifiedEStructuralFeatureName); + + + if (!eStructuralFeature.isRequired()) + { + if (mMayAttribute == null) + { + mMayAttribute = new BasicAttribute(M_MAY); + } + mMayAttribute.add( normalizedEStructuralFeatureName ); + } + else + { + if (mMustAttribute == null) + { + mMustAttribute = new BasicAttribute(M_MUST); + } + mMustAttribute.add( normalizedEStructuralFeatureName ); + } + } + if (mMayAttribute != null) + { + objectClassAttributes.put( mMayAttribute ); + } + if (mMustAttribute != null) + { + objectClassAttributes.put( mMustAttribute ); + } + + } + + + /** + * Checks if is E class processed. + * + * @param processedEClassifiers the processed E classifiers + * @param eClass the e class + * + * @return true, if is E class processed + */ + public static boolean isEClassProcessed( + EClass eClass, + List<EClass> processedEClassifiers) + { + return processedEClassifiers.contains( eClass ); + } + + /** + * Creates the inheritance meta data. + * + * @param metaContext the das model meta context + * @param eClass the e class + * + * @throws NamingException the naming exception + */ + public static void createInheritanceMetaData( + DirContext metaContext, + EClass eClass) + throws NamingException + { + EClass eClassParent = + EcoreTypeSystemHelper.getEClassParent( eClass ); + + String rdn = null; + + if (eClassParent != null) + { + DirContext eClassParentMetaContext = + null; + try + { + eClassParentMetaContext = + ( DirContext ) + metaContext. + lookup(eClassParent.getName()); + } + catch ( NamingException e ) + { + rdn = + CN + "=" + eClassParent.getName(); + + eClassParentMetaContext = + ( DirContext ) + metaContext. + createSubcontext( rdn ); + } + + rdn = CN + "=" + eClass.getName(); + + eClassParentMetaContext. + createSubcontext( rdn ); + } + } +}
\ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EReferenceTypeCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EReferenceTypeCreator.java new file mode 100644 index 0000000000..74c7faff71 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EReferenceTypeCreator.java @@ -0,0 +1,95 @@ +/* + * 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.das.ldap.schema.emf.create; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.constants.SyntaxOIDValues; +import org.apache.tuscany.das.ldap.schema.create.AbstractAttributeTypeCreator; +import org.apache.tuscany.das.ldap.schema.create.SimpleTypeRDNCreator; +import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer; +import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EReference; + +public class EReferenceTypeCreator +extends AbstractAttributeTypeCreator +implements SyntaxOIDValues +{ + public EReferenceTypeCreator() + { + super(); + } + + public void create( + DirContext attributeTypesContext, + EReference eReference, + String oidPrefix) + throws NamingException, Exception + { + String eReferenceName = + eReference.getName(); + + EClass eContainingClass = + eReference.getEContainingClass(); + + String eContainingClassName = + eContainingClass.getName(); + + String namespaceURI = + eContainingClass. + getEPackage(). + getNsURI(); + + String qualifiedEReferenceNameURI = + SimpleTypeNamespaceQualifier.qualify( + namespaceURI, + eContainingClassName, + eReferenceName); + + + String normalizedEReferenceName = + QualifiedNameNormalizer. + normalize(qualifiedEReferenceNameURI); + + basicAttributes.put( + M_DESCRIPTION, + eReferenceName); + + basicAttributes.put( + M_SYNTAX, + SYNTAX_STRING_OID_VALUE); + + basicAttributes.put( + M_NAME, + normalizedEReferenceName ); + + String rdn = + SimpleTypeRDNCreator.create( + oidPrefix, + namespaceURI, + eContainingClassName, + eReferenceName); + + attributeTypesContext.createSubcontext( + rdn, + basicAttributes); + } +}
\ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EcoreTypeSystemHelper.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EcoreTypeSystemHelper.java new file mode 100644 index 0000000000..b9e8fac0fa --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/EcoreTypeSystemHelper.java @@ -0,0 +1,388 @@ +/* + * 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.das.ldap.schema.emf.create; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Stack; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.schema.create.SyntaxEntryCreator; +import org.apache.tuscany.das.ldap.schema.emf.destroy.EStructuralFeatureTypeDestroyer; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; + +/** + * The Class EcoreTypeSystemCreatorHelper. + */ +public class EcoreTypeSystemHelper +{ + + /** + * Creates the E data types list. + * + * @param ePackage the e package + * + * @return the list< E data type> + */ + public static List<EDataType> createEDataTypesList( + EPackage ePackage) + { + List<EObject> list = ePackage.eContents(); + List<EDataType> eDataTypes = new ArrayList<EDataType>(); + Iterator<EObject> iterator = list.iterator(); + while (iterator.hasNext()) + { + Object object = iterator.next(); + if (object instanceof EDataType ) + { + eDataTypes.add( ( EDataType ) object ); + } + } + return eDataTypes; + } + + public static void createSyntaxCheckerEntries( + String oidPrefix, + LdapContext syntaxCheckersContext) throws Exception + + { + + } + + /** + * Creates the syntax entries. + * + * @param oidPrefix the oid prefix + * @param eDataTypes the e data types + * @param syntaxesContext the syntaxes context + * + * @throws Exception the exception + */ + public static void createSyntaxEntries( + List<EDataType> eDataTypes, + String oidPrefix, + LdapContext syntaxesContext, + LdapContext syntaxCheckersContext) throws Exception + { + Iterator<EDataType> eDataTypeIterator = + eDataTypes.iterator(); + + String eDataTypeName = + null; + String eDataTypeNamespaceURI = + null; + + while (eDataTypeIterator.hasNext()) + { + EDataType eDataType = + eDataTypeIterator.next(); + eDataTypeName = + eDataType.getName(); + eDataTypeNamespaceURI = + eDataType.getEPackage().getNsURI(); + + SyntaxEntryCreator.create( + oidPrefix, + eDataTypeNamespaceURI, + eDataTypeName, + syntaxesContext, + syntaxCheckersContext); + } + } + + /** + * Creates the E classifiers list. + * + * @param ePackage the e package + * + * @return the list< E class> + */ + public static List<EClass> createEClassifiersList( + EPackage ePackage) + { + List<EObject> list = ePackage.eContents(); + List<EClass> eClassifiers = new ArrayList<EClass>(); + Iterator<EObject> iterator = list.iterator(); + while (iterator.hasNext()) + { + Object object = iterator.next(); + if (object instanceof EClassifier ) + { + eClassifiers.add( ( EClass ) object ); + } + } + return eClassifiers; + } + + /** + * Creates the E classifier entries. + * + * @param eClassifiers the e classifiers + */ + public static void createEClassifierEntries( + List<EClass> eClassifiers) + { + + } + + /** + * Load parent E classifier stack. + * + * @param parentEClassifierStack the parent E classifier stack + * @param eClass the e class + * + * @return the stack< E class> + * + * Note that clients should pass null for the + * parentEClassifierStack argument. The method + * creates the stack when needed, and uses + * it during recursion. + */ + public static Stack<EClass> loadParentEClassifierStack( + EClass eClass, + Stack<EClass> parentEClassifierStack) + { + List<EClass> eClassParents = + eClass.getESuperTypes(); + + if (eClassParents.size() > 0) + { + Iterator<EClass> eClassParentIterator = + eClassParents.iterator(); + + while(eClassParentIterator.hasNext()) + { + EClass parentEClass = + eClassParentIterator.next(); + + if (!parentEClass.isInterface()) + { + if (parentEClassifierStack == null) + { + parentEClassifierStack = new Stack<EClass>(); + } + + parentEClassifierStack.push( parentEClass ); + + eClassParents = parentEClass.getESuperTypes(); + + if (eClassParents.size() == 0) + { + return parentEClassifierStack; + } + else + { + loadParentEClassifierStack( + parentEClass, + parentEClassifierStack ); + } + } + } + } + return parentEClassifierStack; + } + + /** + * Creates the E object class parents. + * + * @param oidPrefix the oid prefix + * @param objectClassesContext the object classes context + * @param eClass the e class + * + * @throws Exception the exception + * @throws NamingException the naming exception + */ + public static void createEObjectClassParents( + DirContext dasModelMetaContext, + DirContext attributeTypesContext, + DirContext objectClassesContext, + EClass eClass, + String oidPrefix) + throws NamingException, Exception + { + Stack<EClass> parentEClassifierStack = + EcoreTypeSystemHelper. + loadParentEClassifierStack( + eClass, + null); + + EClass parentEClass = null; + + for (int i=0; i<parentEClassifierStack.size(); i++) + { + parentEClass = parentEClassifierStack.pop(); + + EObjectClassCreator + eObjectClassCreator = + new EObjectClassCreator(); + + eObjectClassCreator.create( + dasModelMetaContext, + attributeTypesContext, + objectClassesContext, + parentEClass, + null, + oidPrefix); + } + } + + /** + * Creates the attribute types. + * + * @param oidPrefix the oid prefix + * @param eClass the e class + * @param attributeTypesContext the attribute types context + * + * @throws Exception the exception + * @throws NamingException the naming exception + */ + public static void createAttributeTypes( + DirContext attributeTypesContext, + EClass eClass, + String oidPrefix) + throws NamingException, Exception + { + List<EAttribute> eAttributes = + eClass.getEAttributes(); + + Iterator<EAttribute> eAttributeIterator = + eAttributes.iterator(); + + while (eAttributeIterator.hasNext()) + { + EAttribute eAttribute = eAttributeIterator.next(); + + EAttributeTypeCreator + eAttributeTypeCreator = + new EAttributeTypeCreator(); + + eAttributeTypeCreator.create( + attributeTypesContext, + eAttribute, + oidPrefix ); + } + + List<EReference> eReferences = + eClass.getEReferences(); + + Iterator<EReference> eReferenceIterator = + eReferences.iterator(); + + while(eReferenceIterator.hasNext()) + { + EReference eReference = + eReferenceIterator. + next(); + + EReferenceTypeCreator + eReferenceTypeCreator = + new EReferenceTypeCreator(); + + eReferenceTypeCreator.create( + attributeTypesContext, + eReference, + oidPrefix); + } + } + + /** + * Destroy attribute types. + * + * @param oidPrefix the oid prefix + * @param eClass the e class + * @param attributeTypesContext the attribute types context + * + * @throws Exception the exception + * @throws NamingException the naming exception + */ + public static void destroyAttributeTypes( + DirContext attributeTypesContext, + EClass eClass, + String oidPrefix) + throws NamingException, Exception + { + List<EStructuralFeature> + eStructuralFeatures = + eClass. + getEStructuralFeatures(); + + Iterator<EStructuralFeature> + eStructuralFeatureIterator = + eStructuralFeatures.iterator(); + + while (eStructuralFeatureIterator.hasNext()) + { + EStructuralFeature + eStructuralFeature = + eStructuralFeatureIterator.next(); + + EStructuralFeatureTypeDestroyer.destroy( + attributeTypesContext, + eStructuralFeature, + oidPrefix ); + } + } + + /** + * Gets the E class parent. + * + * @param eClass the e class + * + * @return the e class parent + */ + public static EClass getEClassParent(EClass eClass) + { + List<EClass> eClassParents = + eClass.getESuperTypes(); + + if (eClassParents.size() > 0) + { + Iterator<EClass> eClassParentIterator = + eClassParents.iterator(); + + while(eClassParentIterator.hasNext()) + { + EClass parentEClass = + eClassParentIterator.next(); + + if (!parentEClass.isInterface()) + { + return parentEClass; + } + else + { + return null; + } + } + } + return null; + } +} diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/ModelTypeSystemCreator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/ModelTypeSystemCreator.java new file mode 100644 index 0000000000..3a92143dc5 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/create/ModelTypeSystemCreator.java @@ -0,0 +1,56 @@ +/* + * 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.das.ldap.schema.emf.create; + +import java.util.ArrayList; +import java.util.List; + +import javax.naming.ldap.LdapContext; + +import org.eclipse.emf.ecore.EClass; + +public class ModelTypeSystemCreator +{ + private static List<EClass> processedEClassifiers = + new ArrayList<EClass>(); + + public static void create( + LdapContext dasModelMetaContext, + LdapContext attributeTypesContext, + LdapContext objectClassesContext, + List<EClass> eClassifiers, + String oidPrefix) + throws Exception + { + EObjectClassCreator eObjectClassCreator = + new EObjectClassCreator(); + + for (EClass eClass : eClassifiers) + { + eObjectClassCreator.create( + dasModelMetaContext, + attributeTypesContext, + objectClassesContext, + eClass, + processedEClassifiers, + oidPrefix ); + } + } +}
\ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/ECascadingObjectClassDestroyer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/ECascadingObjectClassDestroyer.java new file mode 100644 index 0000000000..1ad3a1eb21 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/ECascadingObjectClassDestroyer.java @@ -0,0 +1,145 @@ +/* + * 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.das.ldap.schema.emf.destroy; + +import java.util.Map; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.directory.DirContext; +import javax.naming.directory.SearchResult; + +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.eclipse.emf.ecore.EClass; + +/** + * The Class ECascadingObjectClassDestroyer. + * + * The purose of this class is to destroy a ObjectClass + * that is the parent of other ObjectClass entries. + * + * It first checks to see whether the EClass instance + * is a parent of other EClassifiers by examining + * whether the metaContext contains the EClass + * instance's name. + * + * If the EClass instance has an an metaContext child entry, + * then this instance is a parent of other EClassifiers. + * Therefore we check to see whether there are EClass + * instances left to delete that inherit from this EClass. + * + * If none are left we delete the parentMetaContext entry. + * If there are more children left, we leave the parentMetaContext + * entry in place and delete the children. + * + * If there is no parentMetaEntryContext, it means that this + * EClass instance does not have any children. Therefore it's + * safe to delete the corresponding ObjectClass. + */ +public class ECascadingObjectClassDestroyer +implements AttributeTypeConstants +{ + + + public static void destroy( + Map<String, EClass> eClassNameToEClassMap, + DirContext metaContext, + DirContext attributeTypesContext, + DirContext objectClassesContext, + EClass eClass, + String oidPrefix) + throws NamingException, Exception + { + String rdn = + null; + DirContext eClassParentMetaContext = + null; + try + { + eClassParentMetaContext = + ( DirContext ) + metaContext. + lookup( CN + "=" + eClass.getName() ); + } + catch (Exception e) + { + //This eClass can be deleted, because it is not used a super class. + } + + if (eClassParentMetaContext == null) + { + EObjectClassDestroyer.destroy( + metaContext, + attributeTypesContext, + objectClassesContext, + eClass, + oidPrefix ); + } + else + { + Attributes searchAttributes = + new BasicAttributes(true); + + searchAttributes.put(new BasicAttribute(CN)); + + NamingEnumeration<SearchResult> childEntries = + eClassParentMetaContext.search("", searchAttributes); + + if (childEntries.hasMore()) + { + while (childEntries.hasMore()) + { + SearchResult childEntry = + childEntries.next(); + + Attributes childEntryAttributes = + childEntry.getAttributes(); + + String eClassName = + ( String ) + childEntryAttributes.get( CN ).get(); + + EClass childEClass = + eClassNameToEClassMap.get( eClassName ); + + destroy( + eClassNameToEClassMap, + metaContext, + attributeTypesContext, + objectClassesContext, + childEClass, + oidPrefix ); + + EObjectClassDestroyer.destroy( + metaContext, + attributeTypesContext, + objectClassesContext, + eClass, + oidPrefix ); + + rdn = CN + "=" + eClass.getName(); + metaContext.destroySubcontext( rdn ); + } + } + } + } +}
\ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/EObjectClassDestroyer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/EObjectClassDestroyer.java new file mode 100644 index 0000000000..16c7f893d6 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/EObjectClassDestroyer.java @@ -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.das.ldap.schema.emf.destroy; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; +import javax.naming.ldap.LdapContext; + +import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants; +import org.apache.tuscany.das.ldap.schema.create.ComplexTypeRDNCreator; +import org.apache.tuscany.das.ldap.schema.emf.create.EcoreTypeSystemHelper; +import org.eclipse.emf.ecore.EClass; + +/** + * The Class EObjectClassDestroyer. + */ +public class EObjectClassDestroyer +implements AttributeTypeConstants +{ + public static void destroy( + DirContext metaContext, + DirContext attributeTypesContext, + DirContext objectClassesContext, + EClass eClass, + String oidPrefix) + throws NamingException, Exception + { + String namespaceURI = + eClass.getEPackage(). + getNsURI(); + + String rdn = + ComplexTypeRDNCreator. + create( + oidPrefix, + namespaceURI, + eClass.getName()); + + objectClassesContext. + destroySubcontext( + rdn); + + EcoreTypeSystemHelper. + destroyAttributeTypes( + attributeTypesContext, + eClass, + oidPrefix ); + + LdapContext parentMetaContext = + null; + + EClass eClassParent = + EcoreTypeSystemHelper. + getEClassParent( eClass ); + + /* + * After destroying the ObjecClass and its attributes + * we must also clean up the meta context. + */ + + if (eClassParent != null) + { + rdn = CN + "=" + eClassParent.getName(); + + parentMetaContext = + ( LdapContext ) + metaContext.lookup( rdn ); + + rdn = CN + "=" + eClass.getName(); + + parentMetaContext.destroySubcontext( rdn ); + } + } +}
\ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/EStructuralFeatureTypeDestroyer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/EStructuralFeatureTypeDestroyer.java new file mode 100644 index 0000000000..2d88bc8803 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/destroy/EStructuralFeatureTypeDestroyer.java @@ -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.das.ldap.schema.emf.destroy; + +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.apache.tuscany.das.ldap.schema.create.AbstractAttributeTypeCreator; +import org.apache.tuscany.das.ldap.schema.create.SimpleTypeRDNCreator; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EStructuralFeature; + +public class EStructuralFeatureTypeDestroyer +extends AbstractAttributeTypeCreator +{ + public static void destroy( + DirContext attributeTypesContext, + EStructuralFeature eStructuralFeature, + String oidPrefix) + throws NamingException, Exception + { + EClass eContainingClass = + eStructuralFeature. + getEContainingClass(); + + String eContainingClassName = + eContainingClass. + getName(); + + String namespaceURI = + eContainingClass. + getEPackage(). + getNsURI(); + + String rdn = + SimpleTypeRDNCreator.create( + oidPrefix, + namespaceURI, + eContainingClassName, + eStructuralFeature.getName()); + + attributeTypesContext.destroySubcontext( + rdn); + } +}
\ No newline at end of file diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/provide/SyntaxOIDProvider.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/provide/SyntaxOIDProvider.java new file mode 100644 index 0000000000..be0da66292 --- /dev/null +++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/schema/emf/provide/SyntaxOIDProvider.java @@ -0,0 +1,62 @@ +package org.apache.tuscany.das.ldap.schema.emf.provide; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.das.ldap.constants.SyntaxOIDValues; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EcorePackage; + +public class SyntaxOIDProvider +implements SyntaxOIDValues { + + private static Map<EClassifier, String> dataTypeToADSSyntaxOIDMap = null; + + private EcorePackage ecorePackage = EcorePackage.eINSTANCE; + + //TODO Make this a singleton + public SyntaxOIDProvider() + { + dataTypeToADSSyntaxOIDMap = + new HashMap<EClassifier, String>(); + + this.create(); + ecorePackage = + EcorePackage.eINSTANCE; + } + + public String getSyntaxOID(EClassifier eClassifier) + { + String syntaxOID = dataTypeToADSSyntaxOIDMap.get(eClassifier); + if (syntaxOID == null) + { + return SYNTAX_STRING_OID_VALUE; + } + return syntaxOID; + } + + private Map<EClassifier, String> create() + { + dataTypeToADSSyntaxOIDMap.put( + EcorePackage.eINSTANCE.getEString(), + SYNTAX_STRING_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + EcorePackage.eINSTANCE.getEInt(), + SYNTAX_INTEGER_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + EcorePackage.eINSTANCE.getEIntegerObject(), + SYNTAX_INTEGER_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + EcorePackage.eINSTANCE.getEBoolean(), + SYNTAX_BOOLEAN_OID_VALUE); + + dataTypeToADSSyntaxOIDMap.put( + EcorePackage.eINSTANCE.getEBooleanObject(), + SYNTAX_BOOLEAN_OID_VALUE); + + return dataTypeToADSSyntaxOIDMap; + } +}
\ No newline at end of file |