You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrf-dev@ws.apache.org by ip...@apache.org on 2004/12/23 23:52:00 UTC

svn commit: r123238 - /incubator/apollo/trunk/src/java/org/apache/ws/util/GenerationUtils.java /incubator/apollo/trunk/src/java/org/apache/ws/util/OperationInfo.java

Author: ips
Date: Thu Dec 23 14:51:59 2004
New Revision: 123238

URL: http://svn.apache.org/viewcvs?view=rev&rev=123238
Log:
utils for codegen

Added:
   incubator/apollo/trunk/src/java/org/apache/ws/util/GenerationUtils.java
   incubator/apollo/trunk/src/java/org/apache/ws/util/OperationInfo.java

Added: incubator/apollo/trunk/src/java/org/apache/ws/util/GenerationUtils.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/util/GenerationUtils.java?view=auto&rev=123238
==============================================================================
--- (empty file)
+++ incubator/apollo/trunk/src/java/org/apache/ws/util/GenerationUtils.java	Thu Dec 23 14:51:59 2004
@@ -0,0 +1,130 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.util;
+
+import org.apache.ws.resource.ResourceDefinition;
+import org.apache.xmlbeans.impl.common.NameUtil;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+/**
+ * TODO
+ *
+ * @author Ian Springer (ian DOT springer AT hp DOT com)
+ */
+public abstract class GenerationUtils
+{
+
+    private static Map s_nsToPrefixMap = new Hashtable();
+
+    public static String getJavaPackageName( String nsURI )
+    {
+        return NameUtil.getPackageFromNamespace( nsURI );
+    }
+
+    /**
+     * Generates a valid concise prefix for the specified namespace URI. Guaranteed to never return the same prefix for
+     * two different namespaces.
+     *
+     * @param nsURI the namespace URI
+     *
+     * @return the prefix
+     */
+    public static String getPrefix( String nsURI )
+    {
+        if ( nsURI == null )
+        {
+            return ( "" );
+        }
+
+        synchronized ( s_nsToPrefixMap )
+        {
+            if ( s_nsToPrefixMap.containsKey( nsURI ) )
+            {
+                return (String) s_nsToPrefixMap.get( nsURI );
+            }
+        }
+
+        String chompedNsURI = nsURI;
+
+        while ( chompedNsURI.length() > 0 &&
+                !Character.isLetterOrDigit( chompedNsURI.charAt( chompedNsURI.length() - 1 ) ) )
+        {
+            chompedNsURI = chompedNsURI.substring( 0, chompedNsURI.length() - 1 );
+        }
+
+        int prefixStartIndex = chompedNsURI.lastIndexOf( '/' );
+
+        if ( prefixStartIndex == -1 )
+        {
+            prefixStartIndex = chompedNsURI.lastIndexOf( '.' );
+        }
+
+        if ( prefixStartIndex == -1 )
+        {
+            prefixStartIndex = chompedNsURI.lastIndexOf( ':' );
+        }
+
+        String prefix = chompedNsURI.substring( prefixStartIndex + 1 );
+
+        for ( int i = 0; i < prefix.length(); i++ )
+        {
+            char currentChar = prefix.charAt( i );
+            if ( !isValidPrefixChar( currentChar ) )
+            {
+                prefix = prefix.replace( currentChar, '-' );
+            }
+        }
+
+        synchronized ( s_nsToPrefixMap )
+        {
+            if ( s_nsToPrefixMap.containsValue( prefix ) )
+            {
+                prefix = manglePrefix( prefix );
+            }
+            s_nsToPrefixMap.put( nsURI, prefix );
+        }
+        return ( prefix );
+    }
+
+    public Map getOperationInfoMap( ResourceDefinition resourceDef )
+    {
+        return null;
+    }
+
+    private static String manglePrefix( String prefix )
+    {
+        String uniquePrefix;
+        synchronized ( s_nsToPrefixMap )
+        {
+            int i = 1;
+            do
+            {
+                uniquePrefix = prefix + ++i;
+            }
+            while ( s_nsToPrefixMap.containsValue( uniquePrefix ) );
+        }
+        return uniquePrefix;
+    }
+
+    private static boolean isValidPrefixChar( char c )
+    {
+        return ( Character.isLetterOrDigit( c ) ) || ( c == '-' )
+                || ( c == '_' ) || ( c == '.' );
+    }
+
+}

Added: incubator/apollo/trunk/src/java/org/apache/ws/util/OperationInfo.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/util/OperationInfo.java?view=auto&rev=123238
==============================================================================
--- (empty file)
+++ incubator/apollo/trunk/src/java/org/apache/ws/util/OperationInfo.java	Thu Dec 23 14:51:59 2004
@@ -0,0 +1,48 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.util;
+
+import org.apache.commons.lang.StringUtils;
+
+import javax.wsdl.Operation;
+import javax.wsdl.Part;
+
+/**
+ * TODO
+ *
+ * @author Ian Springer (ian DOT springer AT hp DOT com)
+ */
+public class OperationInfo
+{
+
+    private String m_methodName;
+
+    public OperationInfo( Operation op )
+    {
+        m_methodName = StringUtils.capitalize( op.getName() );
+    }
+
+    public String getJavaMethodName()
+    {
+        return m_methodName;
+    }
+
+    public String getJavaMethodSignature()
+    {
+
+    }
+
+}

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