cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r603630 - in /incubator/cxf/trunk/rt/javascript/src: main/java/org/apache/cxf/javascript/ test/java/org/apache/cxf/javascript/ test/java/org/apache/cxf/javascript/types/
Date Wed, 12 Dec 2007 14:50:14 GMT
Author: bimargulies
Date: Wed Dec 12 06:50:13 2007
New Revision: 603630

URL: http://svn.apache.org/viewvc?rev=603630&view=rev
Log:
Refactor and add testing to how we generate JavaScript prefixes.

Added:
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/BasicNameManagerTest.java
  (with props)
Modified:
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/BasicNameManager.java
    incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
    incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/BasicNameManager.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/BasicNameManager.java?rev=603630&r1=603629&r2=603630&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/BasicNameManager.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/BasicNameManager.java
Wed Dec 12 06:50:13 2007
@@ -41,11 +41,37 @@
     
     private Map<String, String> nsPrefixMap;
     
-    public BasicNameManager(ServiceInfo service) {
-        this(service, null);
+    /**
+     * For unit testing, we allow a very meaningless version.
+     * Real uses use the factory methods.
+     */
+    BasicNameManager() {
     }
     
-    public BasicNameManager(ServiceInfo service, Endpoint endpoint) {
+    /**
+     * Factory that just takes a service. Used in tools and unit tests.
+     * @param service
+     * @return
+     */
+    public static BasicNameManager newNameManager(ServiceInfo service) {
+        BasicNameManager nameManager = new BasicNameManager();
+        nameManager.initialize(service, null);
+        return nameManager;
+    }
+    
+    /**
+     * 
+     * @param service
+     * @param endpoint
+     * @return
+     */
+    public static BasicNameManager newNameManager(ServiceInfo service, Endpoint endpoint)
{
+        BasicNameManager nameManager = new BasicNameManager();
+        nameManager.initialize(service, endpoint);
+        return nameManager;
+    }
+
+    private void initialize(ServiceInfo service, Endpoint endpoint) {
         nsPrefixMap = new HashMap<String, String>();
         if (endpoint != null) {
             JavascriptOptionsFeature options = getOptions(endpoint);
@@ -74,7 +100,7 @@
             defineFallbackPrefix(uri);
         }
     }
-    
+
     private JavascriptOptionsFeature getOptions(Endpoint endpoint) {
         if (endpoint != null) {
             for (AbstractFeature feature : endpoint.getActiveFeatures()) {
@@ -86,9 +112,18 @@
         return new JavascriptOptionsFeature(); // save work and return a default set of options.
     }
 
+    /**
+     * Take a URI and turn it into a JavaScript name prefix.
+     * @param uri input URI.
+     * @return output prefix.
+     */
+    protected String transformURI(String uri) {
+        return uri.replaceAll("http:/*", "").replace("uri:", "").replaceAll("[\\.:/-]", "_");
+    }
+
     private String defineFallbackPrefix(String uri) {
         // this needs more work later. We are bound to annoy someone somehow in this area.
-        String jsPrefix = uri.replace("http:", "").replace("uri:", "").replaceAll("[\\.:/-]",
"_");
+        String jsPrefix = transformURI(uri);
         nsPrefixMap.put(uri, jsPrefix);
         return jsPrefix;
     }

Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java?rev=603630&r1=603629&r2=603630&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java
Wed Dec 12 06:50:13 2007
@@ -126,7 +126,8 @@
             ServiceInfo serviceInfo = endpoint.getService();
             Collection<SchemaInfo> schemata = serviceInfo.getSchemas();
             Endpoint serverEndpoint = findEndpoint(endpoint);
-            BasicNameManager nameManager = new BasicNameManager(serviceInfo, serverEndpoint);
+            // we need to move this to the bus.
+            BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo, serverEndpoint);
             NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo
                 .getXmlSchemaCollection());
             try {

Added: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/BasicNameManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/BasicNameManagerTest.java?rev=603630&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/BasicNameManagerTest.java
(added)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/BasicNameManagerTest.java
Wed Dec 12 06:50:13 2007
@@ -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.cxf.javascript;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Simple tests of the name manager.
+ */
+public class BasicNameManagerTest extends Assert {
+     
+    @Test
+    public void testPrefixGeneration() {
+        BasicNameManager manager = new BasicNameManager();
+        String jsp = manager.transformURI("http://ThisIsA.Test");
+        assertEquals("ThisIsA_Test", jsp);
+        jsp = manager.transformURI("uri:george.bill:fred");
+        assertEquals("george_bill_fred", jsp);
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/BasicNameManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/BasicNameManagerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java?rev=603630&r1=603629&r2=603630&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
Wed Dec 12 06:50:13 2007
@@ -349,7 +349,7 @@
 
     public void loadJavascriptForService(ServiceInfo serviceInfo) {
         Collection<SchemaInfo> schemata = serviceInfo.getSchemas();
-        BasicNameManager nameManager = new BasicNameManager(serviceInfo);
+        BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo);
         NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo
             .getXmlSchemaCollection());
         for (SchemaInfo schema : schemata) {

Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java?rev=603630&r1=603629&r2=603630&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
(original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/types/SerializationTest.java
Wed Dec 12 06:50:13 2007
@@ -196,7 +196,7 @@
         assertEquals(1, serviceInfos.size());
         ServiceInfo serviceInfo = serviceInfos.get(0);
         schemata = serviceInfo.getSchemas();
-        nameManager = new BasicNameManager(serviceInfo);
+        nameManager = BasicNameManager.newNameManager(serviceInfo);
         NamespacePrefixAccumulator prefixAccumulator = 
             new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
         for (SchemaInfo schema : schemata) {



Mime
View raw message