Author: kstam
Date: Tue May  1 05:47:37 2007
New Revision: 534045

URL: http://svn.apache.org/viewvc?view=rev&rev=534045
Log:
Applying patch for SCOUT-23 supplied by Jeff Faath.

Modified:
    
webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java
    
webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java

Modified: 
webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java
URL: 
http://svn.apache.org/viewvc/webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java?view=diff&rev=534045&r1=534044&r2=534045
==============================================================================
--- 
webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java
 (original)
+++ 
webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/util/ScoutJaxrUddiHelper.java
 Tue May  1 05:47:37 2007
@@ -36,6 +36,7 @@
 import org.apache.ws.scout.uddi.Description;
 import org.apache.ws.scout.uddi.HostingRedirector;
 import org.apache.ws.scout.uddi.IdentifierBag;
+import org.apache.ws.scout.uddi.CategoryBag;
 import org.apache.ws.scout.uddi.URLType;
 import org.apache.ws.scout.uddi.TModelInstanceDetails;
 import org.apache.ws.scout.uddi.TModelInstanceInfo;
@@ -310,6 +311,10 @@
                 bs.setServiceKey(serve.getKey().getId());
             }
 
+                       addCategories(serve.getClassifications(), 
bs.addNewCategoryBag());
+
+                   // TODO: need to do ServiceBindings->BindingTemplates
+                   
             log.debug("BusinessService=" + bs.toString());
                } catch (Exception ud) {
             throw new JAXRException("Apache JAXR Impl:", ud);
@@ -364,7 +369,11 @@
                        if (scheme.getDescription() != null && 
scheme.getDescription().getValue() != null) {
                                
emptyDesc.setStringValue(scheme.getDescription().getValue());
                        }
-                       // ToDO: overviewDoc,identifierBag,categoryBag
+
+                       addIdentifiers(scheme.getExternalIdentifiers(), 
tm.addNewIdentifierBag());
+                       addCategories(scheme.getClassifications(), 
tm.addNewCategoryBag());
+                       
+                       // ToDO: overviewDoc
                } catch (Exception ud) {
             throw new JAXRException("Apache JAXR Impl:", ud);
         }
@@ -373,7 +382,7 @@
 
     public static TModel getTModelFromJAXRConcept(Concept scheme)
                        throws JAXRException {
-               TModel tm = TModel.Factory.newInstance();
+       TModel tm = TModel.Factory.newInstance();
                if (scheme == null)
                        return null;
                try {
@@ -405,13 +414,17 @@
                                
emptyDesc.setStringValue(scheme.getDescription().getValue());
                        }
 
-                       // ToDO: overviewDoc,identifierBag,categoryBag
+                       addIdentifiers(scheme.getExternalIdentifiers(), 
tm.addNewIdentifierBag());
+                       addCategories(scheme.getClassifications(), 
tm.addNewCategoryBag());
+
+                       // ToDO: overviewDoc
+
                } catch (Exception ud) {
             throw new JAXRException("Apache JAXR Impl:", ud);
         }
         return tm;
     }
-
+    
     public static BusinessEntity getBusinessEntityFromJAXROrg(Organization org)
                        throws JAXRException {
                BusinessEntity biz = BusinessEntity.Factory.newInstance();
@@ -536,26 +549,10 @@
                                        
emptyDU.setStringValue(link.getExternalURI());
                                }
             }
-                       // External Identifiers
-           Collection exid = org.getExternalIdentifiers();
-           Iterator exiditer = exid.iterator();
-                       while (exiditer.hasNext()) {
-                               ExternalIdentifier ei = (ExternalIdentifier) 
exiditer.next();
-
-                               IdentifierBag ibag = biz.addNewIdentifierBag();
-                               KeyedReference keyr = 
ibag.addNewKeyedReference();
-              Key ekey = ei.getKey();
-                               if (ekey != null && ekey.getId() != null)
-                                       keyr.setTModelKey(ekey.getId());
-                               
-                               if (ei.getValue() != null) {
-              keyr.setKeyValue(ei.getValue());
-                               }
-                               
-                               if (ei.getName() != null && 
ei.getName().getValue() != null) {
-              keyr.setKeyName(ei.getName().getValue());
-           }
-                       }
+                       
+                 addIdentifiers(org.getExternalIdentifiers(), 
biz.addNewIdentifierBag());
+                 addCategories(org.getClassifications(), 
biz.addNewCategoryBag());
+                       
                } catch (Exception ud) {
             throw new JAXRException("Apache JAXR Impl:", ud);
         }
@@ -679,4 +676,109 @@
        return uri;
    }
 
+    /**
+     * According to JAXR Javadoc, there are two types of classification, 
internal and external and they use the Classification, Concept,     
+     * and ClassificationScheme objects.  It seems the only difference between 
internal and external (as related to UDDI) is that the
+     * name/value pair of the categorization is held in the Concept for 
internal classifications and the Classification for external (bypassing
+     * the Concept entirely).
+     * 
+     * The translation to UDDI is simple.  Relevant objects have a category 
bag which contains a bunch of KeyedReferences (name/value pairs).  
+     * These KeyedReferences optionally refer to a tModel that identifies the 
type of category (translates to the ClassificationScheme key).  If
+     * this is set and the tModel doesn't exist in the UDDI registry, then an 
invalid key error will occur when trying to save the object.
+     * 
+     * @param regObj
+     * @param destinationObj
+     * @throws JAXRException
+     */
+    private static void addCategories(Collection classifications, CategoryBag 
cbag) throws JAXRException {
+       try {
+                       if (classifications == null || cbag == null)
+                               return;
+               
+               // Classifications
+                       Iterator classiter = classifications.iterator();
+                       while (classiter.hasNext()) {
+                               Classification classification = 
(Classification) classiter.next();
+                               if (classification != null ) {
+                                       KeyedReference keyr = 
cbag.addNewKeyedReference();
+       
+                                       InternationalStringImpl iname = null;
+                                       String value = null;
+                                       ClassificationScheme scheme = 
classification.getClassificationScheme();
+                                       if (classification.isExternal()) {
+                                               iname = 
(InternationalStringImpl) ((RegistryObject) classification).getName();
+                                               value = 
classification.getValue();
+                                               scheme = 
classification.getClassificationScheme();
+                                       }
+                                       else {
+                                               Concept concept = 
classification.getConcept();
+                                               if (concept != null) {
+                                                       iname = 
(InternationalStringImpl) ((RegistryObject) concept).getName();
+                                                       value = 
concept.getValue();
+                                                       scheme = 
concept.getClassificationScheme();
+                                               }
+                                       }
+       
+                                       String name = iname.getValue();
+                                       if (name != null)
+                                               keyr.setKeyName(name);
+       
+                                       if (value != null)
+                                               keyr.setKeyValue(value);
+                                       
+                                       if (scheme != null) {
+                                               Key key = scheme.getKey();
+                                               if (key != null && key.getId() 
!= null)
+                                                       
keyr.setTModelKey(key.getId());
+                                       }
+                               }
+                       }
+       } catch (Exception ud) {
+                       throw new JAXRException("Apache JAXR Impl:", ud);
+               }
+    }
+       
+    /**
+     * Adds the objects identifiers from JAXR's external identifier collection
+     * 
+     * @param identifiers
+     * @param ibag
+     * @throws JAXRException
+     */
+    private static void addIdentifiers(Collection identifiers, IdentifierBag 
ibag) throws JAXRException {
+       try {
+                       if (identifiers == null || ibag == null)
+                               return;
+               
+               // Identifiers
+                       Iterator iditer = identifiers.iterator();
+                       while (iditer.hasNext()) {
+                               ExternalIdentifier extid = (ExternalIdentifier) 
iditer.next();
+                               if (extid != null ) {
+                                       KeyedReference keyr = 
ibag.addNewKeyedReference();
+       
+                                       InternationalStringImpl iname = 
(InternationalStringImpl) ((RegistryObject) extid).getName();
+                                       String value = extid.getValue();
+                                       ClassificationScheme scheme = 
extid.getIdentificationScheme();
+       
+                                       String name = iname.getValue();
+                                       if (name != null)
+                                               keyr.setKeyName(name);
+       
+                                       if (value != null)
+                                               keyr.setKeyValue(value);
+                                       
+                                       if (scheme != null) {
+                                               Key key = scheme.getKey();
+                                               if (key != null && key.getId() 
!= null)
+                                                       
keyr.setTModelKey(key.getId());
+                                       }
+                               }
+                       }
+       } catch (Exception ud) {
+                       throw new JAXRException("Apache JAXR Impl:", ud);
+               }
+    }
+
+    
 }

Modified: 
webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java
URL: 
http://svn.apache.org/viewvc/webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java?view=diff&rev=534045&r1=534044&r2=534045
==============================================================================
--- 
webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java
 (original)
+++ 
webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java
 Tue May  1 05:47:37 2007
@@ -31,6 +31,7 @@
 import org.apache.ws.scout.uddi.DiscoveryURL;
 import org.apache.ws.scout.uddi.DiscoveryURLs;
 import org.apache.ws.scout.uddi.IdentifierBag;
+import org.apache.ws.scout.uddi.CategoryBag;
 import org.apache.ws.scout.uddi.KeyedReference;
 import org.apache.ws.scout.uddi.Name;
 import org.apache.ws.scout.uddi.ServiceInfo;
@@ -131,22 +132,9 @@
       }
 
 
-      //External Identifiers
-      IdentifierBag ibag = entity.getIdentifierBag();
-      if (ibag != null)
-      {
-         KeyedReference[] keyrarr = ibag.getKeyedReferenceArray();
-         for (int i = 0; keyrarr != null && i < keyrarr.length; i++)
-         {
-            KeyedReference keyr = (KeyedReference)keyrarr[i];
-            ExternalIdentifier eid = new ExternalIdentifierImpl(lcm);
-            String kkey = keyr.getTModelKey();
-            if (kkey != null) eid.setKey(new KeyImpl(kkey));
-            eid.setValue(keyr.getKeyValue());
-            eid.setName(new InternationalStringImpl(keyr.getKeyName()));
-            org.addExternalIdentifier(eid);
-         }
-      }
+      addExternalIdentifiers(entity.getIdentifierBag(), org, lcm);
+      addClassifications(entity.getCategoryBag(), org, lcm);
+      
       return org;
    }
 
@@ -222,22 +210,9 @@
          }
       }
 
-      //External Identifiers
-      IdentifierBag ibag = entity.getIdentifierBag();
-      if (ibag != null)
-      {
-         KeyedReference[] keyrarr = ibag.getKeyedReferenceArray();
-         for (int i = 0; keyrarr != null && i < keyrarr.length; i++)
-         {
-            KeyedReference keyr = (KeyedReference)keyrarr[i];
-            ExternalIdentifier eid = new ExternalIdentifierImpl(lcm);
-            String kkey = keyr.getTModelKey();
-            if (kkey != null) eid.setKey(new KeyImpl(kkey));
-            eid.setValue(keyr.getKeyValue());
-            eid.setName(new InternationalStringImpl(keyr.getKeyName()));
-            org.addExternalIdentifier(eid);
-         }
-      }
+      addExternalIdentifiers(entity.getIdentifierBag(), org, lcm);
+      addClassifications(entity.getCategoryBag(), org, lcm);
+      
       return org;
    }
 
@@ -281,6 +256,8 @@
           serve.addServiceBinding(getServiceBinding(bindingTemplate, lcm));
       }
       
+      addClassifications(bs.getCategoryBag(), serve, lcm);
+      
       return serve;
    }
 
@@ -351,6 +328,9 @@
 
       Description desc = getDescription(tmodel);
          if( desc != null ) 
concept.setDescription(lcm.createInternationalString(desc.getStringValue()));
+
+          addExternalIdentifiers(tmodel.getIdentifierBag(), concept, lcm);
+         addClassifications(tmodel.getCategoryBag(), concept, lcm);
       }
 
       return concept;
@@ -366,6 +346,9 @@
       Description desc = getDescription(tmodel);
       
concept.setDescription(lcm.createInternationalString(desc.getStringValue()));
 
+      addExternalIdentifiers(tmodel.getIdentifierBag(), concept, lcm);
+         addClassifications(tmodel.getCategoryBag(), concept, lcm);
+
       return concept;
    }
 
@@ -386,4 +369,62 @@
       return desc;
    }
 
+   /**
+    * Classifications - going to assume all are external since UDDI does not 
use "Concepts".
+    * 
+    * @param cbag
+    * @param destinationObj
+    * @param lcm
+    * @throws JAXRException
+    */
+   private static void addClassifications(CategoryBag cbag, RegistryObject 
destinationObj, LifeCycleManager lcm) throws JAXRException {
+      if (cbag != null) {
+          KeyedReference[] keyrarr = cbag.getKeyedReferenceArray();
+          for (int i = 0; keyrarr != null && i < keyrarr.length; i++)
+          {
+             KeyedReference keyr = (KeyedReference)keyrarr[i];
+             Classification classification = new ClassificationImpl(lcm);
+             classification.setValue(keyr.getKeyValue());
+             classification.setName(new 
InternationalStringImpl(keyr.getKeyName()));
+             
+             String tmodelKey = keyr.getTModelKey();
+             if (tmodelKey != null) {
+                ClassificationScheme scheme = new 
ClassificationSchemeImpl(lcm);
+                scheme.setKey(new KeyImpl(tmodelKey));
+                classification.setClassificationScheme(scheme);
+             }
+             destinationObj.addClassification(classification);
+          }
+      }
+   }
+   
+   /**
+    * External Identifiers
+    * 
+    * @param ibag
+    * @param destinationObj
+    * @param lcm
+    * @throws JAXRException
+    */
+   private static void addExternalIdentifiers(IdentifierBag ibag, 
RegistryObject destinationObj, LifeCycleManager lcm) throws JAXRException {
+      if (ibag != null) {
+          KeyedReference[] keyrarr = ibag.getKeyedReferenceArray();
+          for (int i = 0; keyrarr != null && i < keyrarr.length; i++)
+          {
+             KeyedReference keyr = (KeyedReference)keyrarr[i];
+             ExternalIdentifier extId = new ExternalIdentifierImpl(lcm);
+             extId.setValue(keyr.getKeyValue());
+             extId.setName(new InternationalStringImpl(keyr.getKeyName()));
+             
+             String tmodelKey = keyr.getTModelKey();
+             if (tmodelKey != null) {
+                ClassificationScheme scheme = new 
ClassificationSchemeImpl(lcm);
+                scheme.setKey(new KeyImpl(tmodelKey));
+                extId.setIdentificationScheme(scheme);
+             }
+             destinationObj.addExternalIdentifier(extId);
+          }
+      }
+   }
+   
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to