summaryrefslogtreecommitdiffstats
path: root/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util
diff options
context:
space:
mode:
Diffstat (limited to 'das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util')
-rw-r--r--das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/ComplexTypeNamespaceQualifier.java39
-rw-r--r--das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/IDGenerator.java10
-rw-r--r--das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/JNDIUtil.java168
-rw-r--r--das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/LDAPNormalizer.java38
-rw-r--r--das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/QualifiedNameNormalizer.java36
-rw-r--r--das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/SimpleTypeNamespaceQualifier.java39
-rw-r--r--das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceToInitialContextTransformer.java49
-rw-r--r--das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceURITokenizer.java26
8 files changed, 405 insertions, 0 deletions
diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/ComplexTypeNamespaceQualifier.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/ComplexTypeNamespaceQualifier.java
new file mode 100644
index 0000000000..1185d968d3
--- /dev/null
+++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/ComplexTypeNamespaceQualifier.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.das.ldap.util;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class DataTypeNamespaceQualifier.
+ */
+public class ComplexTypeNamespaceQualifier
+{
+ /**
+ * Qualify.
+ *
+ * @param namespaceURI the namespace URI
+ * @param complexTypeName the name
+ *
+ * @return the string
+ */
+ public static String qualify(String namespaceURI, String complexTypeName )
+ {
+ return namespaceURI + "/" + complexTypeName;
+ }
+}
diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/IDGenerator.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/IDGenerator.java
new file mode 100644
index 0000000000..f41d192bd0
--- /dev/null
+++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/IDGenerator.java
@@ -0,0 +1,10 @@
+package org.apache.tuscany.das.ldap.util;
+
+public class IDGenerator {
+
+ static long currentID= System.currentTimeMillis();
+
+ static public synchronized long generate(){
+ return currentID++;
+ }
+}
diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/JNDIUtil.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/JNDIUtil.java
new file mode 100644
index 0000000000..be19f0b6c4
--- /dev/null
+++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/JNDIUtil.java
@@ -0,0 +1,168 @@
+
+package org.apache.tuscany.das.ldap.util;
+
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+
+/**
+ * The Class JNDIUtil.
+ */
+public class JNDIUtil
+{
+ /**
+ * Calculate DN components.
+ *
+ * @param context the context
+ *
+ * @return the string[] containing the components of the DN
+ *
+ * @throws NamingException the naming exception
+ */
+ public static String[] calculateDNComponents(
+ DirContext context)
+ throws NamingException
+ {
+ String contextDN =
+ context.getNameInNamespace();
+
+ String[] initialContextComponents =
+ contextDN.split( "[,]" );
+
+ return initialContextComponents;
+ }
+
+
+ /**
+ * Calculate DN components.
+ *
+ * @param contextDN the context DN
+ *
+ * @return the string[] containing the components of the DN
+ *
+ * @throws NamingException the naming exception
+ */
+ public static String[] calculateDNComponents(
+ String contextDN)
+ throws NamingException
+ {
+ String[] initialContextComponents =
+ contextDN.split( "[,]" );
+
+ return initialContextComponents;
+ }
+
+ /**
+ * Gets the parent context.
+ *
+ * @param partitionContext the partition context
+ * @param childContext the child context
+ *
+ * @return the parent context (Null if the child context is the root)
+ *
+ * @throws NamingException the naming exception
+ */
+ public static DirContext getParentContext(
+ DirContext childContext,
+ DirContext partitionContext)
+ throws NamingException
+ {
+ String[] childContextDNComponents =
+ calculateDNComponents( childContext );
+
+ String[] partitionDNComponents =
+ calculateDNComponents( partitionContext );
+
+ DirContext parentContext = null;
+
+ if (childContextDNComponents.length == partitionDNComponents.length)
+ {
+ return null;
+ }
+ else if ( (childContextDNComponents.length - 1) == partitionDNComponents.length)
+ {
+ return partitionContext;
+ }
+ else
+ {
+ String parentLookupDN =
+ calculateParentRelativeDN(
+ childContext, partitionContext.getNameInNamespace() );
+
+
+
+ parentContext =
+ ( DirContext ) partitionContext.lookup( parentLookupDN );
+ }
+ return parentContext;
+ }
+
+
+ /**
+ * Calculate parent relative DN.
+ * The parent relative DN is the
+ * DN of the parent context, relative
+ * to the partition context.
+ *
+ * So if the partition context is
+ * <i>ou=system</i> and
+ * the child context has DN
+ * <i>cn=accounts, cn=users, cn=example, ou=system</i>
+ *
+ * then the parent relative DN is
+ * <i>cn=users, cn=example</i>
+ *
+ * @param childContext the child context
+ * @param partitionDN the partition DN
+ *
+ * @return the string
+ *
+ * @throws NamingException the naming exception
+ */
+ public static String calculateParentRelativeDN(
+ DirContext childContext,
+ String partitionDN)
+ throws NamingException
+ {
+ String parentRelativeDN = null;
+
+ String[] childContextDNComponents =
+ calculateDNComponents( childContext );
+
+ String[] partitionDNComponents =
+ calculateDNComponents( partitionDN );
+
+ if (childContextDNComponents.length ==
+ partitionDNComponents.length)
+ {
+ return null;
+ }
+ else if (childContextDNComponents.length ==
+ partitionDNComponents.length + 1)
+ {
+ String childRDN = childContextDNComponents[0];
+ String childContextDN = childContext.getNameInNamespace();
+
+ int beginIndex = childRDN.length() + 1;
+ int endIndex = childContextDN.length();
+
+ parentRelativeDN = childContextDN.substring(
+ beginIndex, endIndex );
+
+ return parentRelativeDN;
+ }
+ else
+ {
+ String childRDN = childContextDNComponents[0];
+ String childContextDN = childContext.getNameInNamespace();
+
+ int beginIndex = childRDN.length() + 1;
+ int endIndex =
+ childContextDN.length() -
+ ( partitionDN.length() +1);
+
+ parentRelativeDN = childContextDN.substring(
+ beginIndex, endIndex );
+ }
+ return parentRelativeDN;
+ }
+}
diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/LDAPNormalizer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/LDAPNormalizer.java
new file mode 100644
index 0000000000..2d0be469bc
--- /dev/null
+++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/LDAPNormalizer.java
@@ -0,0 +1,38 @@
+/*
+ * 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.util;
+
+public class LDAPNormalizer
+{
+
+ /**
+ * Normalize a qualified string for LDAP
+ * by replacing periods with dashes.
+ *
+ * @param qualifiedName the qualified name
+ */
+ public static void normalize(String qualifiedName)
+ {
+ qualifiedName = qualifiedName.replace( ".", "-" );
+ }
+
+
+
+}
diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/QualifiedNameNormalizer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/QualifiedNameNormalizer.java
new file mode 100644
index 0000000000..51b34f5d0f
--- /dev/null
+++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/QualifiedNameNormalizer.java
@@ -0,0 +1,36 @@
+/*
+ * 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.util;
+
+public class QualifiedNameNormalizer
+{
+ /**
+ * Normalize a qualified string for LDAP
+ * by replacing periods with dashes.
+ *
+ * @param qualifiedName the qualified name
+ */
+ public static String normalize(String qualifiedName)
+ {
+ qualifiedName = qualifiedName.replace("http://", "");
+ qualifiedName = qualifiedName.replace("/", "-");
+ return qualifiedName.replace(".", "-");
+ }
+}
diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/SimpleTypeNamespaceQualifier.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/SimpleTypeNamespaceQualifier.java
new file mode 100644
index 0000000000..40dc6e0b09
--- /dev/null
+++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/SimpleTypeNamespaceQualifier.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.das.ldap.util;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class DataTypeNamespaceQualifier.
+ */
+public class SimpleTypeNamespaceQualifier
+{
+ /**
+ * Qualify.
+ *
+ * @param namespaceURI the namespace URI
+ * @param complexTypeName the name
+ *
+ * @return the string
+ */
+ public static String qualify(String namespaceURI, String complexTypeName, String simpleTypeName )
+ {
+ return namespaceURI + "/" + complexTypeName + "/" + simpleTypeName;
+ }
+}
diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceToInitialContextTransformer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceToInitialContextTransformer.java
new file mode 100644
index 0000000000..87ff89071a
--- /dev/null
+++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceToInitialContextTransformer.java
@@ -0,0 +1,49 @@
+
+package org.apache.tuscany.das.ldap.util;
+
+import org.eclipse.emf.common.util.URI;
+
+/**
+ * The Class XSDNamespaceToInitialContextTransformer.
+ *
+ * Takes the XSD Namespace used by the DataObjects
+ * and transforms it into the DN of the initial context
+ * used for the root DataObject entry.
+ */
+public class XSDNamespaceToInitialContextTransformer
+{
+ /**
+ * Transform.
+ *
+ * @param namespaceURIString the namespace URI string
+ *
+ * @return the DN of the initial context
+ *
+ * @throws Exception the exception
+ */
+ public static String transform(String namespaceURIString) throws Exception
+ {
+ URI namespaceURI = URI.createURI(namespaceURIString);
+ String authority = namespaceURI.authority();
+
+ String path = namespaceURI.path();
+
+ String[] authorityTokens = authority.split( "[.]" );
+ String[] pathTokens = path.split("[/]");
+
+ String DN = new String("");
+
+ for (int i = (pathTokens.length-1); i > 0; i--)
+ {
+ DN = DN + "cn=" + pathTokens[i] + ", ";
+ }
+
+ for (int i = 0; i <= (authorityTokens.length-2); i++)
+ {
+ DN = DN + "cn=" + authorityTokens[i] + ", ";
+ }
+
+ DN = DN + "ou=" + authorityTokens[authorityTokens.length-1];
+ return DN;
+ }
+}
diff --git a/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceURITokenizer.java b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceURITokenizer.java
new file mode 100644
index 0000000000..833cf0e7ae
--- /dev/null
+++ b/das-java/contrib/ldap/das.ldap/src/main/java/org/apache/tuscany/das/ldap/util/XSDNamespaceURITokenizer.java
@@ -0,0 +1,26 @@
+
+package org.apache.tuscany.das.ldap.util;
+
+import org.eclipse.emf.common.util.URI;
+
+public class XSDNamespaceURITokenizer
+{
+
+ public static String[] createAuthorityTokens( URI xsdNamespaceURI )
+ {
+ String authority = xsdNamespaceURI.authority();
+ String[] authorityTokens = authority.split( "[.]" );
+ return authorityTokens;
+ }
+
+ public static String[] createPathTokens(URI xsdNamespace)
+ {
+ String path = xsdNamespace.path();
+ if (path != null)
+ {
+ return path.split("[/]");
+ }
+ else
+ return null;
+ }
+}