ws-scout-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ks...@apache.org
Subject svn commit: r555036 - in /webservices/scout/trunk/scout/src: main/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java main/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java test/java/org/apache/ws/scout/registry/JAXRLocaleTest.java
Date Tue, 10 Jul 2007 18:46:25 GMT
Author: kstam
Date: Tue Jul 10 11:46:24 2007
New Revision: 555036

URL: http://svn.apache.org/viewvc?view=rev&rev=555036
Log:
SCOUT-40, Applying patch by Jarek Gawor to fix incorrect handling of InternationalString.

Added:
    webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/JAXRLocaleTest.java
  (with props)
Modified:
    webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java
    webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java

Modified: webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java
URL: http://svn.apache.org/viewvc/webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java?view=diff&rev=555036&r1=555035&r2=555036
==============================================================================
--- webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java
(original)
+++ webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java
Tue Jul 10 11:46:24 2007
@@ -18,7 +18,6 @@
 
 import java.util.Collection;
 import java.util.Iterator;
-import java.util.Locale;
 import java.util.StringTokenizer;
 
 import javax.xml.registry.JAXRException;
@@ -29,7 +28,9 @@
 import javax.xml.registry.infomodel.EmailAddress;
 import javax.xml.registry.infomodel.ExternalIdentifier;
 import javax.xml.registry.infomodel.ExternalLink;
+import javax.xml.registry.infomodel.InternationalString;
 import javax.xml.registry.infomodel.Key;
+import javax.xml.registry.infomodel.LocalizedString;
 import javax.xml.registry.infomodel.Organization;
 import javax.xml.registry.infomodel.PostalAddress;
 import javax.xml.registry.infomodel.RegistryObject;
@@ -172,16 +173,16 @@
 			if (svc != null && svc.getKey() != null && svc.getKey().getId() != null)
{
               bt.setServiceKey(svc.getKey().getId());
            }
-
-			Description emptyDesc = bt.addNewDescription();
-
-			if (((RegistryObject) serve).getDescription() != null && 
-				((RegistryObject) serve).getDescription().getValue() != null) {
-
-				emptyDesc.setStringValue(((RegistryObject) serve)
-						.getDescription().getValue());
-
-			}
+			
+			InternationalString idesc = ((RegistryObject) serve).getDescription();
+            
+            if (idesc != null) {
+                for (LocalizedString locName : idesc.getLocalizedStrings()) {
+                    Description desc = bt.addNewDescription();
+                    desc.setStringValue(locName.getValue());
+                    desc.setLang(locName.getLocale().getLanguage());                
+                }
+            }
 
 			// SpecificationLink
            Collection slcol = serve.getSpecificationLinks();
@@ -286,24 +287,23 @@
 			Service serve) throws JAXRException {
 		BusinessService bs = BusinessService.Factory.newInstance();
 		try {
-			InternationalStringImpl iname = (InternationalStringImpl) ((RegistryObject) serve)
-					.getName();
-            String name = iname.getValue();
-			// bs.setDefaultNameString( name,
-			// Locale.getDefault().getLanguage());
-			Name emptyName = bs.addNewName();
-			
-			if (name != null) emptyName.setStringValue(name);
-			emptyName.setLang(Locale.getDefault().getLanguage());
-
-			Description emptyDesc = bs.addNewDescription();
-			
-			if (((RegistryObject) serve).getDescription() != null && 
-				((RegistryObject) serve).getDescription().getValue() != null) {
-
-				emptyDesc.setStringValue(((RegistryObject) serve).getDescription()
-						.getValue());
+			InternationalString iname = ((RegistryObject) serve).getName();
+						
+			for (LocalizedString locName : iname.getLocalizedStrings()) {
+			    Name name = bs.addNewName();
+			    name.setStringValue(locName.getValue());
+			    name.setLang(locName.getLocale().getLanguage());                
 			}
+	         
+            InternationalString idesc = ((RegistryObject) serve).getDescription();
+    
+            if (idesc != null) {
+                for (LocalizedString locName : idesc.getLocalizedStrings()) {
+                    Description desc = bs.addNewDescription();
+                    desc.setStringValue(locName.getValue());
+                    desc.setLang(locName.getLocale().getLanguage());                
+                }
+            }
 
             Organization o = serve.getProvidingOrganization();
 
@@ -370,21 +370,22 @@
                 tm.setOperator(s.getName());
             }
 
-			InternationalStringImpl iname = (InternationalStringImpl) ((RegistryObject) scheme)
-					.getName();
-            String name = iname.getValue();
-
-			Name emptyName = tm.addNewName();
-			
-			if (name != null) {
-				emptyName.setStringValue(name);
+			InternationalString iname = ((RegistryObject) scheme).getName();
+			 
+			for (LocalizedString locName : iname.getLocalizedStrings()) {
+			    Name name = tm.addNewName();
+			    name.setStringValue(locName.getValue());
+			    name.setLang(locName.getLocale().getLanguage());                
 			}
-			emptyName.setLang(Locale.getDefault().getLanguage());
-
-			Description emptyDesc = tm.addNewDescription();
+	         
+			InternationalString idesc = ((RegistryObject) scheme).getDescription();
 			
-			if (scheme.getDescription() != null && scheme.getDescription().getValue() != null)
{
-				emptyDesc.setStringValue(scheme.getDescription().getValue());
+			if (idesc != null) {
+			    for (LocalizedString locName : idesc.getLocalizedStrings()) {
+			        Description desc = tm.addNewDescription();
+			        desc.setStringValue(locName.getValue());
+	                desc.setLang(locName.getLocale().getLanguage());                
+	            }
 			}
 
 			tm.setIdentifierBag(getIdentifierBagFromExternalIdentifiers(scheme.getExternalIdentifiers()));
@@ -414,22 +415,23 @@
 			if (sl2 != null && sl2.getName() != null)
 				tm.setOperator(sl2.getName());
 
-			InternationalStringImpl iname = (InternationalStringImpl) ((RegistryObject) scheme)
-					.getName();
-            String name = iname.getValue();
-
-			Name emptyName = tm.addNewName();
+			InternationalString iname = ((RegistryObject) scheme).getName();
 			
-			if (name != null) {
-				emptyName.setStringValue(name);
+			for (LocalizedString locName : iname.getLocalizedStrings()) {
+			    Name name = tm.addNewName();
+			    name.setStringValue(locName.getValue());
+			    name.setLang(locName.getLocale().getLanguage());			    
 			}
-			emptyName.setLang(Locale.getDefault().getLanguage());
-
-			Description emptyDesc = tm.addNewDescription();
 			
-			if (scheme.getDescription() != null && scheme.getDescription().getValue() != null)
{
-				emptyDesc.setStringValue(scheme.getDescription().getValue());
-			}
+			InternationalString idesc = ((RegistryObject) scheme).getDescription();
+			
+            if (idesc != null) {
+                for (LocalizedString locName : idesc.getLocalizedStrings()) {
+                    Description desc = tm.addNewDescription();
+                    desc.setStringValue(locName.getValue());
+                    desc.setLang(locName.getLocale().getLanguage());
+                }
+            }
 
 			tm.setIdentifierBag(getIdentifierBagFromExternalIdentifiers(scheme.getExternalIdentifiers()));
 			tm.setCategoryBag(getCategoryBagFromClassifications(scheme.getClassifications()));
@@ -454,21 +456,27 @@
 			if (key != null && key.getId() != null)
 				biz.setBusinessKey(key.getId());
 			// Lets get the Organization attributes at the top level
-            String language = Locale.getDefault().getLanguage();
-
-			Name emptyName = biz.addNewName();
 			
-			if (org.getName() != null && org.getName().getValue() != null) {
-				emptyName.setStringValue(org.getName().getValue());
+			InternationalString iname = org.getName();
+			
+			if (iname != null) {    
+			    for (LocalizedString locName : iname.getLocalizedStrings()) {
+			        Name name = biz.addNewName();
+			        name.setStringValue(locName.getValue());
+			        name.setLang(locName.getLocale().getLanguage());                
+			    }
 			}
-			emptyName.setLang(language);
-
-			Description emptyDesc = biz.addNewDescription();
 			
-			if (org.getDescription() != null && org.getDescription().getValue() != null) {
-				emptyDesc.setStringValue(org.getDescription().getValue());
+			InternationalString idesc = org.getDescription();
+			
+			if (idesc != null) {
+			    for (LocalizedString locName : idesc.getLocalizedStrings()) {
+			        Description desc = biz.addNewDescription();
+			        desc.setStringValue(locName.getValue());
+			        desc.setLang(locName.getLocale().getLanguage());                
+			    }
 			}
-
+			
 			if (org.getPrimaryContact() != null && 
 				org.getPrimaryContact().getPersonName()!= null &&
 				org.getPrimaryContact().getPersonName().getFullName() != null) {

Modified: webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java
URL: http://svn.apache.org/viewvc/webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java?view=diff&rev=555036&r1=555035&r2=555036
==============================================================================
--- webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java
(original)
+++ webservices/scout/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java
Tue Jul 10 11:46:24 2007
@@ -18,6 +18,7 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Locale;
 
 import javax.xml.registry.JAXRException;
 import javax.xml.registry.LifeCycleManager;
@@ -98,8 +99,12 @@
       Description desc = descarray != null && descarray.length > 0 ? descarray[0]:
null;
 
       Organization org = new OrganizationImpl(lcm);
-      if(name != null ) org.setName(getIString(name, lcm));
-      if( desc != null) org.setDescription(getIString((String)desc.getStringValue(), lcm));
+      if(name != null ) {
+          org.setName(getIString(n.getLang(), name, lcm));
+      }
+      if( desc != null) {
+          org.setDescription(getIString(desc.getLang(), desc.getStringValue(), lcm));
+      }
       org.setKey(lcm.createKey(entity.getBusinessKey()));
 
       //Set Services also
@@ -176,8 +181,12 @@
       Description desc = descarr != null && descarr.length > 0 ? descarr[0] :
null;
 
       Organization org = new OrganizationImpl(lcm);
-      if( name != null ) org.setName(getIString(name, lcm));
-      if( desc != null ) org.setDescription(getIString(desc.getStringValue(), lcm));
+      if( name != null ) {
+          org.setName(getIString(n.getLang(), name, lcm));
+      }
+      if( desc != null ) {
+          org.setDescription(getIString(desc.getLang(), desc.getStringValue(), lcm));
+      }
       org.setKey(lcm.createKey(entity.getBusinessKey()));
 
       //Set Services also
@@ -239,6 +248,12 @@
       return org;
    }
 
+   private static InternationalString getIString(String lang, String str, LifeCycleManager
blm)
+       throws JAXRException
+   {
+       return blm.createInternationalString(getLocale(lang), str);
+   }
+   
    public static InternationalString getIString(String str, LifeCycleManager blm)
            throws JAXRException
    {
@@ -263,12 +278,14 @@
 
       if (n != null) {
     	  String name = n.getStringValue();
-      serve.setName(lcm.createInternationalString(name));
+    	  serve.setName(lcm.createInternationalString(getLocale(n.getLang()), name));
       }
 
       Description[] descarr = bs.getDescriptionArray();
       Description desc = descarr != null && descarr.length > 0 ? descarr[0] :
null;
-      if(desc != null ) serve.setDescription(lcm.createInternationalString(desc.getStringValue()));
+      if (desc != null ) {
+          serve.setDescription(lcm.createInternationalString(getLocale(desc.getLang()), desc.getStringValue()));
+      }
       
       //Populate the ServiceBindings for this Service
       BindingTemplates bts = bs.getBindingTemplates();
@@ -301,7 +318,7 @@
 
       if (n != null) {
     	  String name = n.getStringValue();
-      service.setName(lcm.createInternationalString(name));
+    	  service.setName(lcm.createInternationalString(getLocale(n.getLang()), name));
       }
 
       return service;
@@ -347,10 +364,12 @@
       
       if (tmodel != null) {
     	  concept.setKey(lcm.createKey(tmodel.getTModelKey()));
-    	  concept.setName(lcm.createInternationalString(tmodel.getName().getStringValue()));
+    	  concept.setName(lcm.createInternationalString(getLocale(tmodel.getName().getLang()),
tmodel.getName().getStringValue()));
 
     	  Description desc = getDescription(tmodel);
-    	  if( desc != null ) concept.setDescription(lcm.createInternationalString(desc.getStringValue()));
+    	  if( desc != null ) {
+    	      concept.setDescription(lcm.createInternationalString(getLocale(desc.getLang()),
desc.getStringValue()));
+    	  }
 
           concept.addExternalIdentifiers(getExternalIdentifiers(tmodel.getIdentifierBag(),
lcm));
           concept.addClassifications(getClassifications(tmodel.getCategoryBag(), lcm));
@@ -363,11 +382,11 @@
    {
       Concept concept = new ConceptImpl(lcm);
       concept.setKey(lcm.createKey(tmodel.getTModelKey()));
-      concept.setName(lcm.createInternationalString(tmodel.getName().getStringValue()));
+      concept.setName(lcm.createInternationalString(getLocale(tmodel.getName().getLang()),
tmodel.getName().getStringValue()));
 
       Description desc = getDescription(tmodel);
       if (desc != null) {
-          concept.setDescription(lcm.createInternationalString(desc.getStringValue()));
+          concept.setDescription(lcm.createInternationalString(getLocale(desc.getLang()),
desc.getStringValue()));
       }
       
       concept.addExternalIdentifiers(getExternalIdentifiers(tmodel.getIdentifierBag(), lcm));
@@ -381,7 +400,7 @@
    {
       Concept concept = new ConceptImpl(lcm);
       concept.setKey(lcm.createKey(tm.getTModelKey()));
-      concept.setName(lcm.createInternationalString(tm.getName().getStringValue()));
+      concept.setName(lcm.createInternationalString(getLocale(tm.getName().getLang()), tm.getName().getStringValue()));
 
       return concept;
    }
@@ -457,4 +476,13 @@
       return extidentifiers;
    }
    
+   private static Locale getLocale(String lang) {
+       if (lang == null || lang.trim().length() == 0) {
+           return Locale.getDefault();
+       } else if (lang.equalsIgnoreCase(Locale.getDefault().getLanguage())) {
+           return Locale.getDefault();
+       } else {
+           return new Locale(lang);
+       } 
+   }
 }

Added: webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/JAXRLocaleTest.java
URL: http://svn.apache.org/viewvc/webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/JAXRLocaleTest.java?view=auto&rev=555036
==============================================================================
--- webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/JAXRLocaleTest.java
(added)
+++ webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/JAXRLocaleTest.java
Tue Jul 10 11:46:24 2007
@@ -0,0 +1,199 @@
+/**
+ *
+ * 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.scout.registry;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Locale;
+
+import javax.xml.registry.BulkResponse;
+import javax.xml.registry.BusinessLifeCycleManager;
+import javax.xml.registry.BusinessQueryManager;
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.JAXRResponse;
+import javax.xml.registry.LifeCycleManager;
+import javax.xml.registry.RegistryService;
+import javax.xml.registry.infomodel.Concept;
+import javax.xml.registry.infomodel.InternationalString;
+import javax.xml.registry.infomodel.Key;
+import javax.xml.registry.infomodel.Organization;
+import javax.xml.registry.infomodel.Service;
+
+import org.apache.ws.scout.BaseTestCase;
+
+/**
+ */
+public class JAXRLocaleTest extends BaseTestCase
+{
+    private BusinessLifeCycleManager blm = null;
+
+    public void setUp()
+    {
+       super.setUp();
+    }
+
+    public void tearDown()
+    {
+        super.tearDown();
+    }
+
+    public void testPublishOrganizationAndService() throws Exception {
+        login();
+
+        RegistryService rs = connection.getRegistryService();
+        BusinessQueryManager bqm = rs.getBusinessQueryManager();
+        blm = rs.getBusinessLifeCycleManager();
+
+        InternationalString is;
+        BulkResponse br;
+        Key key;
+        Locale locale = Locale.GERMAN;
+
+        // create Organization
+        
+        Organization organization = (Organization) blm.createObject(BusinessLifeCycleManager.ORGANIZATION);
+
+        is = getIString(locale, "Apache Scout Org");
+        organization.setName(is);
+        is = getIString(locale, "This is the org for Apache Scout Test");
+        organization.setDescription(is);
+
+        Collection<Organization> organizations = new ArrayList<Organization>();
+        organizations.add(organization);
+
+        br = blm.saveOrganizations(organizations);
+        checkResponse(br);
+
+        assertEquals(1, br.getCollection().size());
+        key = (Key) br.getCollection().iterator().next();
+
+        Organization organization1 = (Organization) bqm.getRegistryObject(key.getId(), LifeCycleManager.ORGANIZATION);
+
+        System.out.println(organization1.getName().getValue() + " " + organization1.getDescription().getValue());
+        
+        assertEquals(organization.getName().getValue(locale),
+                     organization1.getName().getValue(locale));
+        
+        assertEquals(organization.getDescription().getValue(locale), 
+                     organization1.getDescription().getValue(locale));
+                       
+        // create Service
+        Service service = (Service) blm.createObject(BusinessLifeCycleManager.SERVICE);
+
+        is = getIString(locale, "Apache Scout Service");
+        service.setName(is);
+        is = getIString(locale, "This is the service for Apache Scout Test");
+        service.setDescription(is);
+
+        organization1.addService(service);
+        
+        Collection<Service> services = new ArrayList<Service>();
+        services.add(service);
+
+        br = blm.saveServices(services);
+        checkResponse(br);
+
+        assertEquals(1, br.getCollection().size());
+        key = (Key) br.getCollection().iterator().next();
+
+        Service service1 = (Service) bqm.getRegistryObject(key.getId(), LifeCycleManager.SERVICE);
+
+        System.out.println(service1.getName().getValue() + " " + service1.getDescription().getValue());
+        
+        assertEquals(service.getName().getValue(locale),
+                     service1.getName().getValue(locale));
+        
+        assertEquals(service.getDescription().getValue(locale), 
+                     service1.getDescription().getValue(locale));
+        
+    }
+    
+    public void testPublishConcept() throws Exception {
+        login();
+
+        RegistryService rs = connection.getRegistryService();
+        BusinessQueryManager bqm = rs.getBusinessQueryManager();
+        blm = rs.getBusinessLifeCycleManager();
+
+        Locale locale = Locale.GERMAN;
+
+        Concept concept = (Concept) blm.createObject(BusinessLifeCycleManager.CONCEPT);
+        InternationalString is;
+
+        is = getIString(locale, "Apache Scout Concept -- APACHE SCOUT TEST");
+        concept.setName(is);
+        is = getIString(locale, "This is the concept for Apache Scout Test");
+        concept.setDescription(is);
+
+        Collection<Concept> concepts = new ArrayList<Concept>();
+        concepts.add(concept);
+
+        BulkResponse br = blm.saveConcepts(concepts);
+        checkResponse(br);
+
+        assertEquals(1, br.getCollection().size());
+        Key key = (Key) br.getCollection().iterator().next();
+
+        Concept concept1 = (Concept) bqm.getRegistryObject(key.getId(), LifeCycleManager.CONCEPT);
+
+        System.out.println(concept1.getName().getValue() + " " + concept1.getDescription().getValue());
+
+        /*
+         * XXXX: This does not work properly as Juddy does not store the xml:lang attribute
+         * in its data structure (or db) for a Concept. 
+         */
+         // assertEquals(concept.getName().getValue(locale),
+         //              concept1.getName().getValue(locale));         
+
+        assertEquals(concept.getDescription().getValue(locale), 
+                     concept1.getDescription().getValue(locale));
+    }
+
+    private void checkResponse(BulkResponse br) throws JAXRException {
+        if (br.getStatus() == JAXRResponse.STATUS_SUCCESS)
+        {
+            System.out.println("Object saved.");
+            Collection coll = br.getCollection();
+            Iterator iter = coll.iterator();
+            while (iter.hasNext())
+            {
+                Key key = (Key) iter.next();
+                System.out.println("Saved Key=" + key.getId());
+            }//end while
+        } else
+        {
+            System.err.println("JAXRExceptions " +
+                    "occurred during save:");
+            Collection exceptions = br.getExceptions();
+            Iterator iter = exceptions.iterator();
+            while (iter.hasNext())
+            {
+                Exception e = (Exception) iter.next();
+                System.err.println(e.toString());
+                fail(e.toString());
+            }
+        }
+    }
+
+    private InternationalString getIString(Locale locale, String str)
+            throws JAXRException
+    {
+        return blm.createInternationalString(locale, str);
+    }
+
+}

Propchange: webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/JAXRLocaleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



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


Mime
View raw message