You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Luciano Resende <lu...@gmail.com> on 2007/08/02 00:26:58 UTC

Re: Use the contribution URI as the scope for HelperContext, was Fwd: svn commit: r561111 - /incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOPostProcessor.java

I have fixed this under revision #561972, we now utilize the
contribution file name or it's location (in case of a folder) to
construct the contribution URI.

On 7/30/07, Luciano Resende <lu...@gmail.com> wrote:
>    Looks like DefaultSCADomain is always setting contributionURI to
> empty string. With the current behavior, can we have side effects by
> using the contributionURI as the scope for HelperContext ?
>
>    Here is a output I get after setting a System.out inside
> DefaultSCADomain(line 113) and ImportSDOPostProcessor (line 117), and
> then executing the helloworld-ws-sdo sample.
>
> contributionURI =>
> HelperContext ID:
> contributionURI =>
> HelperContext ID:
> addServletMapping port: 8085 path: /HelloWorldService
> Injected helloWorldService
> Called getGreetings
>
> Thoughts ?
>
> ---------- Forwarded message ----------
> From: rfeng@apache.org <rf...@apache.org>
> Date: Jul 30, 2007 1:48 PM
> Subject: svn commit: r561111 -
> /incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOPostProcessor.java
> To: tuscany-commits@ws.apache.org
>
>
> Author: rfeng
> Date: Mon Jul 30 13:48:15 2007
> New Revision: 561111
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=561111
> Log:
> Use the contribution URI as the scope for HelperContext
>
> Modified:
>     incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOPostProcessor.java
>
> Modified: incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOPostProcessor.java
> URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOPostProcessor.java?view=diff&rev=561111&r1=561110&r2=561111
> ==============================================================================
> --- incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOPostProcessor.java
> (original)
> +++ incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOPostProcessor.java
> Mon Jul 30 13:48:15 2007
> @@ -32,16 +32,17 @@
>  import commonj.sdo.impl.HelperProvider;
>
>  /**
> - * PostProcessor resposible for identifying SDO Factories and
> register them with SDO Helper Context
> + * PostProcessor resposible for identifying SDO Factories and
> register them with
> + * SDO Helper Context
>   *
>   * @version $Rev$ $Date$
>   */
>  public class ImportSDOPostProcessor implements ContributionPostProcessor {
>      private static final String URI_SEPARATOR = "/";
>      private static final String JAVA_SEPARATOR = ".";
> -
> +
>      private HelperContextRegistry helperContextRegistry;
> -
> +
>      public ImportSDOPostProcessor(HelperContextRegistry
> helperContextRegistry) {
>          super();
>          this.helperContextRegistry = helperContextRegistry;
> @@ -58,10 +59,10 @@
>                  if (clazz.getClass() != null) {
>                      try {
>                          //check if it's a SDO factory by
> introspecting INSTANCE field
> -                        if(isSDOFactory(clazz.getJavaClass())) {
> -                            register(clazz.getJavaClass(),
> this.getHelperContext());
> +                        if (isSDOFactory(clazz.getJavaClass())) {
> +                            register(clazz.getJavaClass(),
> this.getHelperContext(contribution));
>                          }
> -
> +
>                      } catch (Exception e) {
>                          e.printStackTrace();
>                      }
> @@ -71,7 +72,9 @@
>      }
>
>      /**
> -     * Transform class artifact URI into a java class name for proper
> loading by the class loader
> +     * Transform class artifact URI into a java class name for proper
> loading by
> +     * the class loader
> +     *
>       * @param factoryURI
>       * @return
>       */
> @@ -80,39 +83,37 @@
>          int pos = factoryURI.lastIndexOf(JAVA_SEPARATOR);
>          return factoryURI.substring(0, pos);
>      }
> -
> +
>      /**
>       * Check if a specific class is a SDO Factory by checking INSTANCE field
> +     *
>       * @param factoryClass
>       * @return
>       */
>      private boolean isSDOFactory(Class factoryClass) {
> -        Field field = null;
>          try {
> -            field = factoryClass.getField("INSTANCE");
> -        } catch (Exception e) {
> -            // ignore any exception
> -        }
> -
> -        if (field != null) {
> +            // The factory interface has a constant "INSTANCE" field
> +            Field field = factoryClass.getField("INSTANCE");
> +            // A public method: register(HelperContext scope)
> +            Method method = factoryClass.getMethod("register",
> HelperContext.class);
>              return true;
> -        } else {
> +        } catch (NoSuchMethodException e) {
> +            return false;
> +        } catch (NoSuchFieldException e) {
>              return false;
>          }
> -
>      }
> -
> +
>      /**
>       * Get a SDO HelperContext reference
> +     *
>       * @return
>       */
> -    private HelperContext getHelperContext() {
> +    private HelperContext getHelperContext(Contribution contribution) {
>          HelperContext helperContext = null;
>
> -        // FIXME: [rfeng] How to get the enclosing composite?
> -        int id = System.identityHashCode(getClass());
> -        // FIXME: [rfeng] How to associate the TypeHelper with deployment
> -        // context?
> +        // FIXME: [rfeng] Should we scope the HelperContext by
> contribution URI?
> +        String id = contribution.getURI();
>          synchronized (helperContextRegistry) {
>              helperContext = helperContextRegistry.getHelperContext(id);
>              if (helperContext == null) {
> @@ -120,12 +121,13 @@
>                  helperContextRegistry.register(id, helperContext);
>              }
>          }
> -
> +
>          return helperContext;
>      }
> -
> +
>      /**
>       * Register an SDO Factory with the helper context
> +     *
>       * @param factoryClass
>       * @param helperContext
>       * @throws Exception
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-commits-help@ws.apache.org
>
>
>
> --
> Luciano Resende
> Apache Tuscany Committer
> http://people.apache.org/~lresende
> http://lresende.blogspot.com/
>


-- 
Luciano Resende
Apache Tuscany Committer
http://people.apache.org/~lresende
http://lresende.blogspot.com/

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


Re: Use the contribution URI as the scope for HelperContext, was Fwd: svn commit: r561111 - /incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOPostProcessor.java

Posted by Jean-Sebastien Delfino <js...@apache.org>.
[snip]
Luciano Resende wrote:
> I have fixed this under revision #561972, we now utilize the
> contribution file name or it's location (in case of a folder) to
> construct the contribution URI.
>
> On 7/30/07, Luciano Resende <lu...@gmail.com> wrote:
>   
>>    Looks like DefaultSCADomain is always setting contributionURI to
>> empty string. With the current behavior, can we have side effects by
>> using the contributionURI as the scope for HelperContext ?
>>
>>    Here is a output I get after setting a System.out inside
>> DefaultSCADomain(line 113) and ImportSDOPostProcessor (line 117), and
>> then executing the helloworld-ws-sdo sample.
>>
>> contributionURI =>
>> HelperContext ID:
>> contributionURI =>
>> HelperContext ID:
>> addServletMapping port: 8085 path: /HelloWorldService
>> Injected helloWorldService
>> Called getGreetings
>>
>> Thoughts ?
>>
>>     

I've just started to look into this and I'm not quite sure how 
associating an SDO HelperContext with a contribution URI is going to 
work. I may be missing something as I've not looked at HelperContext for 
a while.

Here's the scenario that I'm interested in:

- I'm using XSDs to describe my business data, for example 
CustomerBusinessObject.xsd describes http://myns#CustomerBusinessObject 
representing a Customer business object.

- I'm using SDOs as well, and I have generated an SDO class for my 
business objects: myns.CustomerBusinessObject

- I'm using CustomerBusinessObject in all my applications so I have 
packaged CustomerBusinessObject.xsd and myns.CustomerBusinessObject in 
an SCA contribution which I'm going to reuse everywhere: Customer.jar

- I'm developing a CustomerService SCA service component, in 
contribution CustomerService.jar

- CustomerService.jar uses SCA imports to import the Customer business 
object XML namespace and generated SDO class:
<import namespace="http://myns" location="Customer.jar"/>
<import.java package="myns" location="Customer.jar"/>

- the CustomerService component gets the HelperContext associated with 
CustomerService.jar (right?), and uses it to work with a 
CustomerBusinessObject.

Does that basic scenario work? Will the SDO HelperContext obtained in 
CustomerService.jar see the SDO metadata and class for 
CustomerBusinessObject from Customer.jar? I think it should :)

-- 
Jean-Sebastien


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