tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lrese...@apache.org
Subject svn commit: r562520 [4/10] - in /incubator/tuscany/java/das/ldap: ./ das.ldap.configuration.model.ecore.v100/ das.ldap.configuration.model.ecore.v100/model/ das.ldap.configuration.model.ecore.v100/src/ das.ldap.configuration.model.v100/ das.ldap.config...
Date Fri, 03 Aug 2007 16:40:19 GMT
Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/ADSEmbeddedConnection.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/ADSEmbeddedConnection.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/ADSEmbeddedConnection.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/ADSEmbeddedConnection.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,175 @@
+/*
+ *  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.connect;
+
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.server.core.configuration.MutablePartitionConfiguration;
+import org.apache.directory.server.core.configuration.MutableStartupConfiguration;
+import org.apache.directory.server.core.configuration.ShutdownConfiguration;
+import org.apache.log4j.PropertyConfigurator;
+import org.apache.tuscany.model.Configuration;
+
+/**
+ * The Class JNDIEmbeddedConnectionTemplate.
+ */
+public class ADSEmbeddedConnection extends JNDIConnection {
+	private Configuration configuration = null;
+
+	public ADSEmbeddedConnection(Configuration configuration) {
+		super(configuration);
+		this.configuration = configuration;
+	}
+
+	/**
+	 * Shutdown.
+	 * 
+	 * Shuts down an embedded instance of ADS.
+	 * 
+	 * @throws NamingException
+	 *             the naming exception
+	 * @throws Exception
+	 *             the exception
+	 */
+	public void shutdown() throws NamingException, Exception {
+		Hashtable<String, Object> env = new Hashtable<String, Object>();
+
+		env = createEnvironment(env);
+
+		env.put(
+				Context.PROVIDER_URL, 
+				SYSTEM_PROVIDER_PATH);
+		env.put(
+				Context.INITIAL_CONTEXT_FACTORY, 
+				APACHE_CONTEXT_FACTORY);
+		env.putAll(
+				new ShutdownConfiguration().toJndiEnvironment());
+
+		new InitialContext(env);
+		Runtime.getRuntime().gc();
+	}
+
+	/**
+	 * Startup.
+	 * 
+	 * Starts an embedded instance of ADS and creates the the DAS partition, if
+	 * it does not already exist.
+	 * 
+	 * @throws NamingException
+	 *             the naming exception
+	 */
+	public LdapContext startup(String partitionName) 
+	throws NamingException {
+    	PropertyConfigurator.
+    	configure(
+    			configuration.
+    			getNlog4jConfigurationFilePath());
+
+		MutableStartupConfiguration mutableStartupConfiguration = 
+			new MutableStartupConfiguration();
+
+		Hashtable<String, Object> adminEnv = 
+			new Hashtable<String, Object>();
+
+		adminEnv.putAll(mutableStartupConfiguration.toJndiEnvironment());
+
+		adminEnv.put(
+				Context.PROVIDER_URL, 
+				SYSTEM_PROVIDER_PATH);
+		adminEnv.put(
+				Context.SECURITY_PRINCIPAL,
+				configuration.getSecurityPrincipal());
+		adminEnv.put(
+				Context.SECURITY_CREDENTIALS, 
+				configuration.getSecurityCredentials());
+		adminEnv.put(
+				Context.SECURITY_AUTHENTICATION, 
+				configuration.getSecurityAuthenticationType());
+		new InitialLdapContext(adminEnv, null);
+
+		MutablePartitionConfiguration dasPartition = 
+			new MutablePartitionConfiguration();
+
+		Attributes suffixAttributes                            = 
+			new BasicAttributes();
+		suffixAttributes.put(OBJECT_CLASS, TOP);
+		suffixAttributes.get(OBJECT_CLASS).add(ORGANIZATIONAL_UNIT);
+		suffixAttributes.put(OU, partitionName);
+
+		dasPartition.setId(partitionName);
+		dasPartition.setSuffix(getProviderPath(partitionName));
+		dasPartition.setContextEntry(suffixAttributes);
+
+		Set<MutablePartitionConfiguration> partitions = 
+			new HashSet<MutablePartitionConfiguration>();
+
+		partitions.add(dasPartition);
+
+		mutableStartupConfiguration.setPartitionConfigurations(partitions);
+
+		Hashtable<String, Object> env                           = 
+			new Hashtable<String, Object>();
+
+		env.put(
+				Context.INITIAL_CONTEXT_FACTORY,
+				"org.apache.directory.server.core.jndi.CoreContextFactory");
+		env.put(
+				Context.SECURITY_PRINCIPAL, 
+				DEFAULT_SECURITY_PRINCIPAL_VALUE);
+		env.put(
+				Context.SECURITY_CREDENTIALS,
+				DEFAULT_SECURITY_CREDENTIALS_VALUE);
+		env.put(
+				Context.SECURITY_AUTHENTICATION,
+				SIMPLE_SECURITY_AUTHENTICATION_VALUE);
+		env.put(
+				Context.PROVIDER_URL, getProviderPath(partitionName));
+
+		env.put(
+				org.apache.directory.server.core.configuration.Configuration.JNDI_KEY,
+				mutableStartupConfiguration);
+
+		return new InitialLdapContext(env, null);
+	}
+	
+	public LdapContext connect(String partitionName) throws NamingException
+    {
+        return startup(partitionName);
+    }
+    
+	/**
+	 * Gets the provider path. TODO Move to helper
+	 * 
+	 * @return the provider path
+	 */
+	public String getProviderPath(String partitionName) {
+		return OU + "=" + partitionName;
+	}
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/ADSEmbeddedConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/ADSEmbeddedConnection.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/JNDIConnection.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/JNDIConnection.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/JNDIConnection.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/JNDIConnection.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,96 @@
+/*
+ *  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.connect;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+import org.apache.tuscany.model.Configuration;
+
+import org.apache.tuscany.das.ldap.constants.ApacheDSConnectionConstants;
+import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants;
+import org.apache.tuscany.das.ldap.schema.constants.ObjectClassConstants;
+/*
+ * Just a class template class
+ */
+public class JNDIConnection
+implements 
+ApacheDSConnectionConstants, 
+AttributeTypeConstants,
+ObjectClassConstants
+{    
+    private Configuration configuration            = null;
+
+    public JNDIConnection(Configuration configuration)
+    {
+    	this.configuration=configuration;
+    }
+    
+    public Hashtable<String,Object> createEnvironment(
+    		Hashtable<String, Object> env)
+    {
+        env.put( 
+            Context.INITIAL_CONTEXT_FACTORY, 
+            configuration.getInitialContextFactory() );
+
+        env.put( 
+            Context.SECURITY_AUTHENTICATION, 
+            configuration.getSecurityAuthenticationType());
+        
+        env.put( 
+            Context.SECURITY_PRINCIPAL, 
+            configuration.getSecurityPrincipal() );
+        
+        env.put( 
+            Context.SECURITY_CREDENTIALS, 
+            configuration.getSecurityCredentials() );
+        
+        return env;
+    }
+
+    public LdapContext connect(String partitionName) throws NamingException
+    {
+    	Hashtable<String, Object> env = 
+    		new Hashtable<String, Object>();
+    	
+    	env = createEnvironment(env);
+
+    	env.put( 
+                Context.PROVIDER_URL,
+                getProviderURL(partitionName));
+    	
+        return new InitialLdapContext(env, null);
+    }
+
+    public String getProviderURL(String partitionName)
+    {
+    	return "ldap://" + 
+    	configuration.getHost() + 
+    	":" + 
+    	configuration.getPort() + 
+    	"/" + 
+    	OU + 
+    	"=" + 
+    	partitionName;
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/JNDIConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/connect/JNDIConnection.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreator.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreator.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreator.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,75 @@
+/*
+ *  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.create;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.tuscany.das.ldap.util.XSDNamespaceURITokenizer;
+import org.eclipse.emf.common.util.URI;
+
+/**
+ * The InitialContextCreator for a model's directory namespace
+ */
+public class InitialContextCreator
+{
+    /**
+     * Creates the parent context for the root DataObject instance 
+     * 
+     * @param dasContext the dir context
+     * @param xsdNamespace the xml namespace of the DataObjects
+     * 
+     * @return the directory context
+     * 
+     * @throws NamingException the naming exception
+     */
+    public static LdapContext create(
+        String xsdNamespace, 
+        LdapContext dasContext) throws NamingException
+    {
+        URI xsdNamespaceURI      = 
+            URI.createURI( 
+                xsdNamespace );
+        
+        String[] pathTokens      = 
+            XSDNamespaceURITokenizer.
+            createPathTokens( 
+                xsdNamespaceURI );
+        
+        String[] authorityTokens = 
+            XSDNamespaceURITokenizer.
+            createAuthorityTokens( 
+                xsdNamespaceURI );
+        
+        dasContext         = 
+            InitialContextCreatorHelper.
+            createAuthorityContext( 
+                dasContext, 
+                authorityTokens );
+        
+        dasContext         = 
+            InitialContextCreatorHelper.
+            createPathContext( 
+                dasContext, 
+                pathTokens );
+        
+        return dasContext;
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreatorHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreatorHelper.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreatorHelper.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreatorHelper.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,123 @@
+/*
+ *  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.create;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants;
+import org.apache.tuscany.das.ldap.schema.constants.ObjectClassConstants;
+import org.apache.tuscany.das.ldap.schema.constants.SchemaObjectClassConstants;
+
+/**
+ * The Class InitialContextCreatorHelper.
+ */
+public class InitialContextCreatorHelper
+implements
+ObjectClassConstants,
+SchemaObjectClassConstants, 
+AttributeTypeConstants
+{
+    /**
+     * Lookup the subcontext and if it does not exist,
+     * create it.
+     * 
+     * @param ldapContext the dir context
+     * @param subContext the sub context
+     * 
+     * @return the dir context
+     * 
+     * @throws NamingException the naming exception
+     */
+    public static LdapContext createSubContext(
+        LdapContext ldapContext, 
+        String subContext,
+        Attributes attributes) 
+    throws NamingException
+    {
+        try
+        {
+            ldapContext = ( LdapContext ) ldapContext.lookup( subContext );
+        }
+        catch ( NamingException e )
+        {
+            if (attributes == null)
+            {
+                ldapContext = ( LdapContext ) ldapContext.createSubcontext( subContext );                
+            }
+            else
+            {
+                ldapContext = ( LdapContext ) ldapContext.createSubcontext( subContext, attributes );
+            }
+        }
+        return ldapContext;
+    }
+
+    /**
+     * Creates the authority context.
+     * 
+     * @param authorityTokens the authority tokens
+     * @param ldapContext the directory context
+     * 
+     * @return the dir context
+     * 
+     * @throws NamingException the naming exception
+     */
+    public static LdapContext createAuthorityContext(
+    		LdapContext ldapContext, 
+        String[] authorityTokens) 
+    throws NamingException
+    {
+        for (int i = authorityTokens.length-1; i >= (0); i--)
+        {
+            String subContext = CN+ "=" + authorityTokens[i];
+            ldapContext = (LdapContext) createSubContext( 
+            		ldapContext, 
+            		subContext, null );
+        }
+        return ldapContext;
+    }
+    
+    /**
+     * Creates the path context.
+     * 
+     * @param ldapContext the dir context
+     * @param pathTokens the path tokens
+     * 
+     * @return the dir context
+     * 
+     * @throws NamingException the naming exception
+     */
+    public static LdapContext createPathContext(
+    		LdapContext ldapContext, 
+        String[] pathTokens) 
+    throws NamingException
+    {
+        for (int i = 1; i < (pathTokens.length); i++)
+        {
+            String subContext = CN + "=" + pathTokens[i];
+            ldapContext = (LdapContext) createSubContext( 
+            		ldapContext, 
+            		subContext, null );
+        }
+        return ldapContext;
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreatorHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/InitialContextCreatorHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/MetaContextCreator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/MetaContextCreator.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/MetaContextCreator.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/MetaContextCreator.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,53 @@
+/*
+ *  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.create;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.tuscany.das.ldap.constants.DASConstants;
+import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants;
+
+public class MetaContextCreator
+implements 
+DASConstants,
+AttributeTypeConstants
+{
+    public static LdapContext create(
+        LdapContext context) throws NamingException
+    {
+        String rdn   = 
+            CN + "=" + META_CONTEXT_NAME;
+
+        try
+        {
+            return 
+            ( LdapContext ) 
+            context.lookup( rdn );
+        }
+        catch(Exception e)
+        {
+            return
+            ( LdapContext )
+            context.
+            createSubcontext( rdn );
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/MetaContextCreator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/create/MetaContextCreator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/InitialContextDestroyer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/InitialContextDestroyer.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/InitialContextDestroyer.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/InitialContextDestroyer.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,74 @@
+/*
+ *  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.destroy;
+
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+
+import org.apache.tuscany.das.ldap.util.JNDIUtil;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class InitialContextDestroyer.
+ */
+public class InitialContextDestroyer
+{
+    
+    /**
+     * Destroys the initial naming context
+     * when the parent entries do not contain
+     * other child entries.  If the initial
+     * naming context also supports other
+     * entries, then a NamingException will
+     * be thrown.
+     * 
+     * @param partitionContext the partition context
+     * @param initialContext the initial context
+     * 
+     * @throws NamingException the naming exception
+     */
+    public static void destroy(
+        DirContext initialContext, 
+        DirContext partitionContext) 
+    throws NamingException
+    {
+        String[] initialContextComponents = 
+            JNDIUtil.
+            calculateDNComponents( initialContext );
+        
+        String[] partitionContextComponents = 
+            JNDIUtil.calculateDNComponents( partitionContext );
+        
+        int numberOfPossibleSubcontexts = 
+            initialContextComponents.length
+            - partitionContextComponents.length;
+        
+        for (int i = 0; i < numberOfPossibleSubcontexts; i++)
+        {
+            String rdn = initialContextComponents[i];
+            
+            initialContext = JNDIUtil.getParentContext( 
+                initialContext, 
+                partitionContext );
+
+            initialContext.destroySubcontext( rdn );
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/InitialContextDestroyer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/InitialContextDestroyer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/MetaContextDestroyer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/MetaContextDestroyer.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/MetaContextDestroyer.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/MetaContextDestroyer.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,53 @@
+/*
+ *  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.destroy;
+
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+
+import org.apache.tuscany.das.ldap.constants.DASConstants;
+import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants;
+
+/**
+ * The Class MetaContextDestroyer.
+ */
+public class MetaContextDestroyer
+implements 
+DASConstants,
+AttributeTypeConstants
+{
+    /**
+     * Destroys an empty meta context
+     * 
+     * @param initialContext the initial context
+     * 
+     * @throws NamingException the naming exception thrown when the meta context has child entries
+     */
+    public static void destroy(
+        DirContext initialContext) 
+    throws NamingException
+    {
+        String rdn =
+            CN + "=" + META_CONTEXT_NAME;
+
+            initialContext.
+            destroySubcontext( rdn );
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/MetaContextDestroyer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/destroy/MetaContextDestroyer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/Context.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/Context.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/Context.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/Context.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,81 @@
+
+package org.apache.tuscany.das.ldap.emf;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.naming.ldap.LdapContext;
+
+import org.eclipse.emf.ecore.sdo.EDataObject;
+
+public class Context
+{
+    private Map<String, LdapContext> xsdNamespaceToLdapContextMap = null;
+    private Map<EDataObject, String> dataObjectToRelativeDNCache  = null; 
+
+
+    private LdapContext dasContext                 = null;
+    private LdapContext schemaContext              = null;
+    private LdapContext dasMetaContext             = null;
+    private LdapContext ecoreObjectClassesContext  = null;
+    private LdapContext ecoreAttributeTypesContext = null;
+    
+    public Context()
+    {
+        xsdNamespaceToLdapContextMap               = 
+            new Hashtable<String, LdapContext>();
+        
+        dataObjectToRelativeDNCache                = 
+            new Hashtable<EDataObject, String>();
+    }
+
+    public LdapContext getDasContext()
+    {
+        return dasContext;
+    }
+    public void setDasContext( LdapContext dasContext )
+    {
+        this.dasContext = dasContext;
+    }
+    public LdapContext getSchemaContext()
+    {
+        return schemaContext;
+    }
+    public void setSchemaContext( LdapContext schemaContext )
+    {
+        this.schemaContext = schemaContext;
+    }
+    public LdapContext getDasMetaContext()
+    {
+        return dasMetaContext;
+    }
+    public void setDasMetaContext( LdapContext dasMetaContext )
+    {
+        this.dasMetaContext = dasMetaContext;
+    }
+    public LdapContext getEcoreObjectClassesContext()
+    {
+        return ecoreObjectClassesContext;
+    }
+    public void setEcoreObjectClassesContext( LdapContext ecoreObjectClassesContext )
+    {
+        this.ecoreObjectClassesContext = ecoreObjectClassesContext;
+    }
+    public LdapContext getEcoreAttributeTypesContext()
+    {
+        return ecoreAttributeTypesContext;
+    }
+    public void setEcoreAttributeTypesContext( LdapContext ecoreAttributeTypesContext )
+    {
+        this.ecoreAttributeTypesContext = ecoreAttributeTypesContext;
+    }
+    public Map<String, LdapContext> getXsdNamespaceToLdapContextMap()
+    {
+        return xsdNamespaceToLdapContextMap;
+    }
+
+    public Map<EDataObject, String> getDataObjectToRelativeDNCache()
+    {
+        return dataObjectToRelativeDNCache;
+    }
+}

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/Context.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/Context.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDAS.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDAS.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDAS.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDAS.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,379 @@
+/*
+ *  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.emf;
+
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
+import org.apache.tuscany.das.ldap.connect.ADSEmbeddedConnection;
+import org.apache.tuscany.das.ldap.connect.JNDIConnection;
+import org.apache.tuscany.das.ldap.constants.DASConstants;
+import org.apache.tuscany.das.ldap.create.InitialContextCreator;
+import org.apache.tuscany.das.ldap.create.MetaContextCreator;
+import org.apache.tuscany.das.ldap.emf.create.EDataGraphCreator;
+import org.apache.tuscany.das.ldap.emf.read.EDataGraphReader;
+import org.apache.tuscany.das.ldap.emf.update.EDataGraphUpdater;
+import org.apache.tuscany.das.ldap.schema.emf.create.EcoreTypeSystemHelper;
+import org.apache.tuscany.das.ldap.schema.emf.create.ModelTypeSystemCreator;
+import org.apache.tuscany.model.Configuration;
+import org.apache.tuscany.model.DASMeta;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.sdo.EDataGraph;
+import org.eclipse.emf.ecore.sdo.EDataObject;
+
+public class LdapDAS
+implements DASConstants
+{
+    private Map<EDataObject, String> metaDataObjectToRelativeDNCache = null;
+    
+    private Configuration configuration                 = null;
+    private DASMeta dasMeta                             = null;
+    private EDataGraph dasMetaDataGraph                 = null;
+    private Context context                             = null;
+    private ADSEmbeddedConnection adsEmbeddedConnection = null;
+
+	
+	public LdapDAS(Configuration configuration) 
+	throws NamingException 
+	{
+	    metaDataObjectToRelativeDNCache             =
+            new Hashtable<EDataObject, String>();
+	    
+	    
+        this.configuration                          =
+            configuration;
+
+	    context                                     = 
+	        new Context();
+	    
+	    JNDIConnection jndiConnection               = null;
+		
+		if (configuration.isEmbedded())
+		{
+			adsEmbeddedConnection = 
+				new ADSEmbeddedConnection(configuration);
+			context.
+			setDasContext(
+				adsEmbeddedConnection.
+				connect(
+						configuration.
+						getDasPartitionName() ));
+
+			context.
+            setSchemaContext(
+                adsEmbeddedConnection.
+	            connect( 
+	                configuration.
+	                getSchemaPartitionName() ));
+		}
+		else
+		{
+			jndiConnection = 
+				new JNDIConnection(configuration);
+			
+            context.
+            setDasContext(
+				jndiConnection.connect(
+				    configuration.
+				    getDasPartitionName() ));
+
+            context.
+            setSchemaContext(
+				jndiConnection.connect(
+				    configuration.
+				    getSchemaPartitionName() ));
+		}
+
+		context.
+		setDasMetaContext( 
+		    MetaContextCreator.
+		    create(
+		        context.
+		        getDasContext() ));
+		
+		context.setEcoreObjectClassesContext( 
+		    LdapDASHelper.
+		    createEcoreObjectClassesContext( 
+		        context.
+		        getSchemaContext() ));
+		
+		context.setEcoreAttributeTypesContext( 
+            LdapDASHelper.
+            createEcoreAttributeTypesContext( 
+                context.
+                getSchemaContext() ));
+	}
+
+	/**
+	 * Write.
+	 * 
+	 * @param eDataGraph the e data graph
+	 * @param dasContext the das context
+	 * 
+	 * @return the map< E data object, string>
+	 * 
+	 * @throws NamingException the naming exception
+	 * 
+	 * First tries to find a LdapContext that matches the xsdNamespace
+	 * of the DataGraph that is about to be written.  If it finds one, then
+	 * it know that the type system has been written, thus it can skip this 
+	 * step.
+	 * 
+	 * If the LdapContext lookup fails, the type system may still exist
+	 * the check:
+	 * 
+	 * configuration.getSupportedSchemas().contains(xsdNamespace)
+	 * 
+	 * is performed.
+	 * 
+	 * If the supported schema list contains the xsdNamespace, the 
+	 * corresponding the LdapContext parent context of the root DataObject
+	 * instance is created and the DataGraph written.
+	 * 
+	 * If the xsdNamespace is not contained by the supported schemas list,
+	 * a final check is performed to see whether the type system exists.  If this
+	 * check succeeds and exception is thrown, because it should not.  This could happen
+	 * if the configuration write that occurs as the supported schema list is updated failed,
+	 * or the the read of the supported schemas from the DIT failed.
+	 * 
+	 */
+	public void create(
+		EDataGraph eDataGraph) 
+    throws NamingException, Exception
+    {
+
+    	EObject rootEObject     = 
+    	    eDataGraph.
+    	    getERootObject();
+    	
+    	EPackage ePackage       = 
+    	    rootEObject.
+    	    eClass().
+    	    getEPackage();
+    	
+    	String xsdNamespace     = 
+    	    ePackage.
+    	    getNsURI();
+    	
+		LdapContext rootContext = 
+			context.
+			getXsdNamespaceToLdapContextMap().
+			get(xsdNamespace);
+		
+		if (rootContext != null)
+		{
+        	EDataGraphCreator.create(
+    				eDataGraph,
+    				rootContext,
+    				context.
+    				getDataObjectToRelativeDNCache());
+		}
+		
+		/*
+		 * The root context was not yet created so we check if the 
+		 * schema is written for the model instance, and if it is
+		 * we create the root context and add it to the context map.
+		 */
+        metaDataObjectToRelativeDNCache =
+            new Hashtable<EDataObject, String>();
+        
+        dasMetaDataGraph = 
+            LdapDASHelper.readDasMeta( 
+            context, 
+            metaDataObjectToRelativeDNCache );
+        
+        dasMeta = ( DASMeta ) dasMetaDataGraph.getRootObject();
+
+    	if (LdapDASHelper.isSchemaReady(xsdNamespace, dasMeta))
+    	{
+    		rootContext = 
+    			InitialContextCreator.
+    			create(
+    					xsdNamespace, 
+    					context.
+    					getDasContext() );
+    		
+    		context.getXsdNamespaceToLdapContextMap().
+    		put(xsdNamespace, rootContext);
+    		
+        	EDataGraphCreator.create(
+    				eDataGraph,
+    				rootContext,
+    				context.getDataObjectToRelativeDNCache());
+    	}
+    	
+        /*
+         * The model's schema is not yet written (We also do a validation
+         * check to make sure the server is not in an inconsistent state)
+         * so we need to write the schema and then write the model instance.
+         */
+    	
+    	if (LdapDASHelper.isSchemaWritten(
+    			rootEObject.eClass(),
+    			context.
+    			getEcoreObjectClassesContext() ))
+    	{
+    		throw new RuntimeException("This should not happen");//TODO better message + constant
+    	}
+    	
+    	List<EClass> eClassifiers = 
+    		EcoreTypeSystemHelper.
+    		createEClassifiersList(ePackage);
+    	
+		rootContext = 
+			InitialContextCreator.
+			create(
+					xsdNamespace, 
+					context.getDasContext() );
+		
+        context.getXsdNamespaceToLdapContextMap().
+        put(xsdNamespace, rootContext);
+		
+		LdapContext dasModelMetaContext = 
+			MetaContextCreator.
+			create(rootContext);
+    	
+    	ModelTypeSystemCreator.create(
+    			dasModelMetaContext, 
+    			context.getEcoreAttributeTypesContext(), 
+    			context.getEcoreObjectClassesContext(), 
+    			eClassifiers, 
+    			TUSCANY_OID_PREFIX_VALUE);
+    	
+    	dasMetaDataGraph.
+    	getChangeSummary().
+    	beginLogging();
+    	
+    	dasMeta.
+    	getSupportedSchemas().
+    	add(xsdNamespace);
+    	
+    	dasMetaDataGraph.
+        getChangeSummary().
+        endLogging();
+    	
+    	EDataGraphUpdater.update(
+            dasMetaDataGraph,
+            context.getDasMetaContext(),
+            metaDataObjectToRelativeDNCache);
+    	
+        EDataGraphCreator.create(
+            eDataGraph,
+            rootContext,
+            context.
+            getDataObjectToRelativeDNCache());
+
+    }
+	
+
+	public EDataGraph read(
+	    EClass rootDataObjectEClass, 
+	    String id) 
+	throws LdapNameNotFoundException, NamingException
+	{
+	    String xsdNamespace     = 
+	        rootDataObjectEClass.
+	        getEPackage().
+	        getNsURI();
+	    
+	    LdapContext rootContext =
+	        context.
+	        getXsdNamespaceToLdapContextMap().
+	        get(xsdNamespace);
+	    
+	    if (rootContext == null)
+	    {
+            rootContext = 
+                InitialContextCreator.
+                create(
+                        xsdNamespace, 
+                        context.
+                        getDasContext() );
+            
+            context.
+            getXsdNamespaceToLdapContextMap().
+            put(xsdNamespace, rootContext);
+	    }
+	    
+	    return EDataGraphReader.read( 
+	        rootDataObjectEClass, 
+	        id, 
+	        rootContext,
+	        context.
+	        getDataObjectToRelativeDNCache());
+	}
+		
+	public void update(EDataGraph eDataGraph) 
+	throws NamingException
+	{
+	   EDataObject rootDataObject  = 
+	       ( EDataObject ) eDataGraph.getRootObject();
+	   
+	   EClass rootDataObjectEClass = 
+	       rootDataObject.eClass();
+
+       String xsdNamespace     = 
+           rootDataObjectEClass.
+           getEPackage().
+           getNsURI();
+       
+       LdapContext rootContext =
+           context.
+           getXsdNamespaceToLdapContextMap().
+           get(xsdNamespace);
+       
+       if (rootContext == null)
+       {
+           rootContext = 
+               InitialContextCreator.
+               create(
+                       xsdNamespace, 
+                       context.
+                       getDasContext() );
+           
+           context.
+           getXsdNamespaceToLdapContextMap().
+           put(xsdNamespace, rootContext);
+       }
+
+	    EDataGraphUpdater.update( 
+	        eDataGraph, 
+	        rootContext,
+	        context.
+	        getDataObjectToRelativeDNCache());
+	}
+
+    public Context getContext()
+    {
+        return context;
+    }
+
+    public ADSEmbeddedConnection getAdsEmbeddedConnection()
+    {
+        return adsEmbeddedConnection;
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDAS.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDAS.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDASHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDASHelper.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDASHelper.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDASHelper.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,295 @@
+/*
+ *  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.emf;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.tuscany.das.ldap.constants.DASConstants;
+import org.apache.tuscany.das.ldap.emf.create.EDataGraphCreator;
+import org.apache.tuscany.das.ldap.emf.read.EDataGraphReader;
+import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants;
+import org.apache.tuscany.das.ldap.schema.constants.ObjectClassConstants;
+import org.apache.tuscany.das.ldap.schema.constants.SchemaObjectClassConstants;
+import org.apache.tuscany.das.ldap.schema.create.ComplexTypeRDNCreator;
+import org.apache.tuscany.das.ldap.schema.emf.create.EcoreTypeSystemHelper;
+import org.apache.tuscany.das.ldap.schema.emf.create.ModelTypeSystemCreator;
+import org.apache.tuscany.model.ConfigurationFactory;
+import org.apache.tuscany.model.DASMeta;
+import org.apache.tuscany.model.impl.ConfigurationPackageImpl;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.sdo.EDataGraph;
+import org.eclipse.emf.ecore.sdo.EDataObject;
+import org.eclipse.emf.ecore.sdo.SDOFactory;
+
+public class LdapDASHelper
+implements 
+DASConstants, 
+ObjectClassConstants,
+AttributeTypeConstants,
+SchemaObjectClassConstants
+{
+    public static EDataGraph readDasMeta(
+        Context context,
+        Map<EDataObject, String> metaDataObjectToRelativeDNCache) 
+    throws Exception
+    {
+        EDataGraph dasMetaDataGraph = null;
+        
+        try
+        {
+            dasMetaDataGraph                            =
+                EDataGraphReader.read(
+                    ConfigurationPackageImpl.
+                    eINSTANCE.getDASMeta(),  
+                    DAS_META_ID_DEFAULT, 
+                    context.
+                    getDasMetaContext(),
+                    metaDataObjectToRelativeDNCache);
+        }
+        catch(NamingException e)
+        {
+            List<EClass> eClassifiers = 
+                EcoreTypeSystemHelper.
+                createEClassifiersList(
+                    ConfigurationPackageImpl.
+                    eINSTANCE);
+            
+            ModelTypeSystemCreator.
+            create( 
+                context.getDasMetaContext(), 
+                context.getEcoreAttributeTypesContext(), 
+                context.getEcoreObjectClassesContext(), 
+                eClassifiers, 
+                TUSCANY_OID_PREFIX_VALUE );           
+            
+            DASMeta dasMeta = 
+                ConfigurationFactory.
+                INSTANCE.
+                createDASMeta();
+            
+            dasMetaDataGraph =
+                    SDOFactory.
+                    eINSTANCE.
+                    createEDataGraph();
+            
+            dasMetaDataGraph.
+            setERootObject( 
+                ( EObject ) dasMeta );
+            
+            EDataGraphCreator.create(
+                dasMetaDataGraph, 
+                context.
+                getDasMetaContext(),
+                metaDataObjectToRelativeDNCache);
+        }
+        return dasMetaDataGraph;
+    }
+    
+	public static boolean isSchemaReady(
+			String xsdNamespace, 
+			DASMeta dasMeta)
+	{
+		return 
+		dasMeta.
+		getSupportedSchemas().
+		contains(xsdNamespace);
+	}
+	
+	public static boolean isSchemaWritten(
+			EClass eClass,
+			LdapContext ecoreObjectClassesContext)
+	throws Exception
+	{
+		String xsdNamespace      =
+			eClass.getEPackage().getNsURI();
+		
+        String eObjectClassRDN = 
+            ComplexTypeRDNCreator.
+            create(
+                TUSCANY_OID_PREFIX_VALUE,
+                xsdNamespace, 
+                eClass.getName());
+        try {
+            ecoreObjectClassesContext.
+            lookup( eObjectClassRDN );
+        }
+        catch (Exception e)
+        {
+        	return false;
+        }
+        return true;
+	}
+	
+	
+	public static boolean isSchemaSupported(
+	    String xsdNamespaceURI, 
+	    DASMeta dasMeta)
+	{
+		return 
+		dasMeta.
+		getSupportedSchemas().
+		contains(xsdNamespaceURI);
+	}
+
+	public static void initializeSchemaContexts(
+	    LdapContext schemaContext,
+	    LdapContext ecoreObjectClassesContext,
+	    LdapContext ecoreAttributeTypesContext) 
+	throws NamingException
+	{
+	    LdapContext ecoreContext   =
+	        createEcoreContext(schemaContext);
+	    
+	    ecoreObjectClassesContext  = 
+	        createEcoreObjectClassesContext(ecoreContext);
+	    
+	    ecoreAttributeTypesContext = 
+	            createEcoreAttributeTypesContext( ecoreContext );
+	}
+
+	
+	public static LdapContext createEcoreContext(
+	    LdapContext schemaContext) 
+	throws NamingException
+    {
+	    String ecoreContextRDN = 
+	        CN + "=" + ECORE_CONTEXT_NAME;
+	    
+	    try
+	    {
+	        return ( LdapContext ) schemaContext.lookup( ecoreContextRDN );
+	    }
+	    catch (Exception e)
+	    {
+	        //Create the context
+	    }
+
+	    Attributes contextAttributes   = new BasicAttributes();
+        
+        Attribute objectClassAttribute = new BasicAttribute(
+        OBJECT_CLASS, 
+        TOP);
+        objectClassAttribute.add(META_SCHEMA);
+    
+        contextAttributes.put( objectClassAttribute );
+        contextAttributes.put( CN, ECORE_CONTEXT_NAME );
+        
+        return 
+        ( LdapContext ) 
+        schemaContext.
+        createSubcontext(
+            ecoreContextRDN, 
+            contextAttributes );
+    }
+	
+    public static LdapContext createEcoreObjectClassesContext(
+        LdapContext schemaContext) 
+    throws NamingException
+    {
+        LdapContext ecoreContext            =
+            createEcoreContext(schemaContext);
+        
+        String ecoreObjectClassesContextRDN = 
+            OU + "=" + OBJECT_CLASSES_CONTEXT_NAME;
+        
+        try
+        {
+            return 
+            ( LdapContext ) 
+            ecoreContext.
+            lookup( 
+                ecoreObjectClassesContextRDN );
+        }
+        catch (Exception e)
+        {
+            //Create the context
+        }
+
+        Attributes contextAttributes   = new BasicAttributes();
+        
+        Attribute objectClassAttribute = new BasicAttribute(
+        OBJECT_CLASS, 
+        TOP);
+        objectClassAttribute.add(ORGANIZATIONAL_UNIT);
+
+        Attribute ecoreAttribute = new BasicAttribute(
+            OU, 
+            OBJECT_CLASSES_CONTEXT_NAME);
+
+        contextAttributes.put( ecoreAttribute );
+        contextAttributes.put( objectClassAttribute );
+        
+        return 
+        ( LdapContext ) 
+        ecoreContext.
+        createSubcontext( 
+            ecoreObjectClassesContextRDN, 
+            contextAttributes );
+    }
+    
+    public static LdapContext createEcoreAttributeTypesContext(
+        LdapContext schemaContext) 
+    throws NamingException
+    {
+        LdapContext ecoreContext             =
+            createEcoreContext(schemaContext);
+
+        String ecoreAttributeTypesContextRDN = 
+            OU + "=" + ATTRIBUTE_TYPES_CONTEXT_NAME;
+        
+        try
+        {
+            return 
+            ( LdapContext ) 
+            ecoreContext.
+            lookup( 
+                ecoreAttributeTypesContextRDN );
+        }
+        catch (Exception e)
+        {
+            //Create the context
+        }
+
+        Attributes contextAttributes   = new BasicAttributes();
+        
+        Attribute objectClassAttribute = new BasicAttribute(
+        OBJECT_CLASS, 
+        TOP);
+        objectClassAttribute.add(ORGANIZATIONAL_UNIT);
+
+        contextAttributes.put( OU, ATTRIBUTE_TYPES_CONTEXT_NAME );
+        contextAttributes.put( objectClassAttribute );
+        
+        return 
+        ( LdapContext ) 
+        ecoreContext.createSubcontext(
+            ecoreAttributeTypesContextRDN, 
+            contextAttributes );
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDASHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/LdapDASHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreator.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreator.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreator.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,62 @@
+/*
+ *  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.emf.create;
+
+import java.util.Map;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.sdo.EDataGraph;
+import org.eclipse.emf.ecore.sdo.EDataObject;
+
+public class EDataGraphCreator
+implements AttributeTypeConstants
+{
+	public static void create(
+    		EDataGraph eDataGraph, 
+    		LdapContext rootContext,
+    		Map<EDataObject, String> dataObjectToRelativeDNCache) 
+    throws NamingException
+    {
+        EDataObject rootDataObject                =
+        	(EDataObject) 
+        	eDataGraph.getRootObject();
+        
+        EDataObjectCreator.create(
+        		rootDataObject, 
+        		rootContext,
+        		dataObjectToRelativeDNCache);
+        
+        EList<EObject> children                     =
+        	rootDataObject.eContents();
+        
+        if (children.size() > 0)
+        {
+            EDataGraphCreatorHelper.createChildren(
+            		children,
+            		rootContext,
+            		dataObjectToRelativeDNCache);
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreatorHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreatorHelper.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreatorHelper.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreatorHelper.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,97 @@
+/*
+ *  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.emf.create;
+
+import java.util.Map;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.tuscany.das.ldap.schema.constants.AttributeTypeConstants;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.sdo.EDataObject;
+
+public class EDataGraphCreatorHelper
+implements AttributeTypeConstants
+{
+	/*
+	 * TODO Make mutlithreaded
+	 */
+	public static void createChildren(
+			EList<EObject> children,
+			LdapContext rootContext,
+			Map<EDataObject, String> dataObjectToRelativeDNCache) 
+	throws NamingException
+	{
+		LdapContext eContainmentFeatureContext = 
+			null;
+
+		for (EObject eObject : children)
+		{
+			String parentContextRDN                            =
+				dataObjectToRelativeDNCache.get(eObject.eContainer());
+
+			LdapContext parentContext                        =
+				(LdapContext) 
+				rootContext.
+				lookup(parentContextRDN);
+
+			EStructuralFeature eContainmentFeature  =
+				eObject.eContainingFeature();
+				
+			String eContainingFeatureContextName    =
+				CN + "="+ eContainmentFeature.getName();
+			
+			try 
+			{
+				eContainmentFeatureContext                     = 
+					(LdapContext) 
+					parentContext.lookup(
+							eContainingFeatureContextName);
+			}
+			catch (Exception e)
+			{
+				eContainmentFeatureContext                     = 
+					(LdapContext) 
+					parentContext.
+					createSubcontext(
+							eContainingFeatureContextName);
+			}
+
+			EDataObjectCreator.create((
+				EDataObject) eObject, 
+				eContainmentFeatureContext,
+				dataObjectToRelativeDNCache);
+			
+			children                                                          = 
+				eObject.eContents();
+			
+			if ( children.size()> 0)
+			{
+				createChildren(
+						children,
+						rootContext,
+						dataObjectToRelativeDNCache);
+			}
+		}
+	}
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreatorHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataGraphCreatorHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreator.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreator.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreator.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,137 @@
+/*
+ *  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.emf.create;
+
+import java.util.Map;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.tuscany.das.ldap.constants.DASConstants;
+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.sdo.EDataObject;
+
+public class EDataObjectCreator
+implements DASConstants
+{
+    /**
+     * Create the LDAP entry for the EDataObject argument
+     * 
+     * @param eDataObject the e data object
+     * @param containerContext the container context
+     * 
+     * @throws NamingException the naming exception
+     */
+    public static void create(
+    		EDataObject eDataObject, 
+    		LdapContext containerContext,
+    		Map<EDataObject, String> dataObjectToRelativeDNCache) 
+    throws NamingException
+    {
+    	String rdn                                                     =
+            null;
+        Object dataObjectID                                   =
+            null;
+        
+        EClass eClass                                              = 
+            eDataObject.eClass();
+        
+    	EAttribute idEAttribute                              =
+        	eClass.getEIDAttribute();
+        
+        String namespaceURI                                  =
+            eClass.getEPackage().getNsURI();
+        
+        String qualifiedEAttributeName                 =
+            null;
+        String normalizedEAttributeName             =
+            null;
+
+        Attributes attributes                                   =
+            new BasicAttributes();
+        
+        attributes                                                     =
+        	EDataObjectCreatorHelper.processEAttributes(
+        			attributes, 
+        			eDataObject, 
+        			eClass, 
+        			namespaceURI);
+        
+        attributes                                                     =
+        	EDataObjectCreatorHelper.processEReferences(
+        			attributes, 
+        			eDataObject, 
+        			eClass, 
+        			namespaceURI);
+           
+        String qualifiedEClassName                        =
+            ComplexTypeNamespaceQualifier.
+            qualify( 
+                namespaceURI, 
+                eClass.getName() );
+        
+        String normalizedEClassName                   =
+        	QualifiedNameNormalizer.
+        	normalize(qualifiedEClassName);
+
+        Attribute objectClassAttribute                  =
+        	new BasicAttribute("objectClass");
+        
+        objectClassAttribute.
+        add(normalizedEClassName);
+        
+        attributes.put(objectClassAttribute);
+        
+        dataObjectID                                               =
+            eDataObject.eGet(idEAttribute );
+        
+        qualifiedEAttributeName                            =
+            SimpleTypeNamespaceQualifier.
+            qualify( 
+                namespaceURI, 
+                eClass.getName(), 
+                idEAttribute.getName() );
+        
+        normalizedEAttributeName                        =
+        	QualifiedNameNormalizer.
+        	normalize(qualifiedEAttributeName);
+        
+        rdn                                                                 = 
+        	normalizedEAttributeName + "=" + dataObjectID;  
+        
+        containerContext.createSubcontext( 
+            rdn, 
+            attributes );
+        
+        EDataObjectCreatorHelper.
+        updateDataObjectToRelativeDNCache(
+        		eDataObject, 
+        		dataObjectToRelativeDNCache, 
+        		rdn);
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreatorHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreatorHelper.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreatorHelper.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreatorHelper.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,284 @@
+/*
+ *  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.emf.create;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+
+import org.apache.tuscany.das.ldap.constants.DASConstants;
+import org.apache.tuscany.das.ldap.util.QualifiedNameNormalizer;
+import org.apache.tuscany.das.ldap.util.SimpleTypeNamespaceQualifier;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.sdo.EDataObject;
+
+public class EDataObjectCreatorHelper
+implements DASConstants
+{
+	
+	public static void updateDataObjectToRelativeDNCache(
+			EDataObject eDataObject,
+			Map<EDataObject, String> dataObjectToRelativeDNCache,
+			String rdn)
+	{
+        EDataObject parentDataObject = 
+        	(EDataObject) eDataObject.eContainer();
+        
+	    if (parentDataObject !=null)
+	    {
+	    	String parentRDN = 
+	    		dataObjectToRelativeDNCache.
+	    		get(parentDataObject);
+	    	rdn                         = 
+	    		rdn + 
+	    		"," + 
+	    		"cn=" + 
+	    		eDataObject.eContainingFeature().getName() + 
+	    		"," +  
+	    		parentRDN;
+	    	dataObjectToRelativeDNCache.put(eDataObject, rdn);
+	    }
+	    else 
+	    {
+	    	dataObjectToRelativeDNCache.put(eDataObject, rdn);
+	    }
+	}
+    
+    
+    /**
+     * Process EAttributes adding the normalized EAttribute instance's
+     * name and corresponding values to the attributes argument.
+     * 
+     * @param attributes the attributes
+     * @param eDataObject the e data object
+     * @param eClass the e class
+     * @param namespaceURI the namespace URI
+     * 
+     * @return the attributes
+     * 
+     * @throws NamingException the naming exception
+     * 
+     * Note that ApacheDS supports the Syntaxes (DataTypes) 
+     * Boolean, Integer, String.  This means that all values that
+     * are not Boolean or Integer are stored as Strings.
+     */
+    public static Attributes processEAttributes(
+    		Attributes attributes,
+    		EDataObject eDataObject,
+    		EClass eClass,
+    	    String namespaceURI) 
+    throws NamingException
+    {
+        EcorePackage ecorePackage                   =
+        	EcorePackage.eINSTANCE;
+        
+    	EAttribute idEAttribute                     =
+        	eClass.getEIDAttribute();
+        
+        List<EAttribute> eAttributes                = 
+            eClass.getEAllAttributes();
+        
+        String qualifiedEAttributeName              =
+            null;
+        String normalizedEAttributeName             =
+            null;
+
+        for (EAttribute eAttribute : eAttributes)
+        {
+        	Attribute attribute = 
+        		processEAttribute(
+        				eAttribute, 
+        				namespaceURI, 
+        				eClass, eDataObject);
+        	attributes.put(attribute);
+        }
+		return attributes;
+    }
+    
+    /*
+     * TODO This is also used in updates so consider moving to a utility
+     */
+    public static Attribute processEAttribute(
+    		EAttribute eAttribute,
+    		String namespaceURI,
+    		EClass eClass,
+    		EDataObject eDataObject)
+    {
+        String qualifiedEAttributeName                     =
+            SimpleTypeNamespaceQualifier.
+            qualify( 
+                namespaceURI, 
+                eClass.getName(), 
+                eAttribute.getName() );
+        
+        String normalizedEAttributeName                    =
+        	QualifiedNameNormalizer.
+        	normalize(qualifiedEAttributeName);
+        
+        Attribute attribute                                = 
+        	new BasicAttribute(normalizedEAttributeName);
+        
+        if (eAttribute.isMany())
+        {
+            if ( !(eAttribute.getEType() == EcorePackage.eINSTANCE.getEBoolean() || 
+                         eAttribute.getEType() == EcorePackage.eINSTANCE.getEBooleanObject() ) )
+            {
+                EList<Object> eAttributeValues             = 
+                    ( EList<Object> ) eDataObject.eGet( eAttribute );
+                
+                for (Object eAttributeValue : eAttributeValues)
+                {
+                    attribute.add(eAttributeValue.toString() );
+                }
+            }
+            else
+            {
+                EList<Boolean> eAttributeValues             = 
+                    ( EList<Boolean> ) eDataObject.eGet( eAttribute );
+                
+                for (Boolean eAttributeValue : eAttributeValues)
+                {
+                    if (eAttributeValue == false)
+                    {
+                        attribute.add(Boolean.FALSE.toString().toUpperCase() );
+                    }
+                    else
+                    {
+                        attribute.add(Boolean.TRUE.toString().toUpperCase() );
+                    }
+                }
+            }
+            return attribute;
+        }
+    
+    	if ( !(eAttribute.getEType() == EcorePackage.eINSTANCE.getEBoolean() || 
+    	     eAttribute.getEType() == EcorePackage.eINSTANCE.getEBooleanObject() ) )
+    	{
+            Object eAttributeValue                        = 
+                eDataObject.eGet( eAttribute );
+            
+            attribute.add(eAttributeValue.toString() );
+    	}
+    	else
+    	{
+            Boolean eAttributeValue                      = 
+                (Boolean) eDataObject.eGet( eAttribute );
+            
+            if (eAttributeValue == false)
+            {
+                attribute.add(Boolean.FALSE.toString().toUpperCase() );
+            }
+            else
+            {
+                attribute.add(Boolean.TRUE.toString().toUpperCase() );
+            }
+    	}
+    	return attribute;
+    }
+    
+    /**
+     * Process references adding the normalized EReference instance's
+     * name and corresponding id (IDs for multiplicity many references)
+     * to the attributes argument.
+     * 
+     * @param attributes the attributes
+     * @param eDataObject the e data object
+     * @param eClass the e class
+     * @param namespaceURI the namespace URI
+     * 
+     * @return the attributes
+     */
+    public static Attributes processEReferences(
+    		Attributes attributes,
+    		EDataObject eDataObject,
+    		EClass eClass,
+    	    String namespaceURI)
+    {
+        List<EReference> eReferences   =
+        	eClass.getEAllReferences();
+        
+        for (EReference eReference : eReferences)
+        {
+        	String qualifiedEReferenceName                   =
+                SimpleTypeNamespaceQualifier.
+                qualify( 
+                    namespaceURI, 
+                    eClass.getName(), 
+                    eReference.getName() );
+            
+            String normalizedEReferenceName                =
+            	QualifiedNameNormalizer.
+            	normalize(qualifiedEReferenceName);
+        	
+            if (eReference.isMany())
+            {
+            	List<EDataObject> referencedEDataObjects =
+            		(List<EDataObject>) eDataObject.eGet(eReference);
+            	
+            	Attribute idAttribute                                        =
+            		new BasicAttribute(normalizedEReferenceName);
+
+            	for (EDataObject containedEDataObject : referencedEDataObjects)
+            	{
+            		EClass containedEDataObjectEClass          =
+                		containedEDataObject.eClass();
+                	
+                	String containedEDataObjectID                   =
+                		(String) containedEDataObject.eGet(
+        					containedEDataObjectEClass.
+        					getEIDAttribute());
+                	
+                	idAttribute.add(containedEDataObjectID);
+            	}
+            	attributes.put(idAttribute);
+            }
+            else
+            {
+            	EDataObject containedEDataObject          =
+            		(EDataObject) 
+            		eDataObject.eGet(eReference);
+
+            	if (containedEDataObject != null)
+            	{
+                	EClass containedEDataObjectEClass      =
+                		containedEDataObject.eClass();
+                	
+                	String containedEDataObjectID               =
+                		(String) containedEDataObject.eGet(
+        					containedEDataObjectEClass.
+        					getEIDAttribute());
+                	
+                	attributes.put(
+                			normalizedEReferenceName, 
+                			containedEDataObjectID);
+            	}
+            }
+        }
+		return attributes;
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreatorHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/create/EDataObjectCreatorHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataGraphReader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataGraphReader.java?view=auto&rev=562520
==============================================================================
--- incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataGraphReader.java (added)
+++ incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataGraphReader.java Fri Aug  3 09:40:00 2007
@@ -0,0 +1,131 @@
+/*
+ *  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.emf.read;
+
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
+import org.apache.tuscany.das.ldap.constants.DASConstants;
+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;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.sdo.EDataGraph;
+import org.eclipse.emf.ecore.sdo.EDataObject;
+import org.eclipse.emf.ecore.sdo.SDOFactory;
+
+public class EDataGraphReader
+implements DASConstants
+{
+    public static EDataGraph read(
+    		EClass rootDataObjectEClass,
+    		String id,
+    		LdapContext rootContext,
+    		Map<EDataObject, String> dataObjectToRelativeDNCache) 
+    throws NamingException, LdapNameNotFoundException
+    {
+    	EDataGraph eDataGraph                     =
+        		SDOFactory.eINSTANCE.createEDataGraph();
+
+    	String namespaceURI                       =
+            rootDataObjectEClass.getEPackage().
+            getNsURI();
+
+        EAttribute idEAttribute                   =
+    		rootDataObjectEClass.getEIDAttribute();
+
+        String qualifiedIDEAttributeName          =
+            SimpleTypeNamespaceQualifier.
+            qualify( 
+                namespaceURI, 
+                rootDataObjectEClass.getName(), 
+                idEAttribute.getName() );
+        
+    	String normalizedIDEAttributeName         =
+        	QualifiedNameNormalizer.
+        	normalize(qualifiedIDEAttributeName);
+        
+    	String eDataObjectRDN                     = 
+        	normalizedIDEAttributeName + "=" + id;
+        
+        LdapContext eDataObjectContext            =
+        	(LdapContext) 
+        	rootContext.
+        	lookup(eDataObjectRDN);
+        
+        Attributes attributes                     = 
+        	rootContext.
+        	getAttributes(eDataObjectRDN);
+        
+        Map<EDataObject, Map<EStructuralFeature, List<String>>> crossReferenceIDCache                      =
+        	new Hashtable<EDataObject, Map<EStructuralFeature, List<String>>>();
+
+    	EDataObject rootDataObject          =
+    		EDataGraphReaderHelper.
+    		restoreEDataObject(
+    				crossReferenceIDCache,
+    				rootDataObjectEClass, 
+    				namespaceURI, 
+    				attributes);
+
+        String relativeDN                          =
+        	EDataGraphReaderHelper.calculateRelativeDN(
+        			rootContext, 
+        			eDataObjectContext);
+        
+        dataObjectToRelativeDNCache.
+        put(rootDataObject, relativeDN);
+    	
+    	List<EReference> eReferences               =
+    		rootDataObjectEClass.getEAllContainments();
+    	
+    	if (rootDataObjectEClass.getEAllContainments().size() > 0)
+    	{
+    		EDataGraphReaderHelper.
+        	addContainmentDataObjects(
+        			crossReferenceIDCache,
+        			dataObjectToRelativeDNCache,
+        			rootDataObject, 
+        			attributes, 
+        			namespaceURI, 
+        			eDataObjectContext,
+        			rootContext);
+    	}
+
+    	eDataGraph.setERootObject(rootDataObject);
+
+    	Resource resource = eDataGraph.getRootResource();
+    	
+    	EDataGraphReaderHelper.restoreCrossReferences(
+    			crossReferenceIDCache, 
+    			resource);
+
+    	return eDataGraph;
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataGraphReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/das/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/emf/read/EDataGraphReader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message