You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by pc...@apache.org on 2003/12/11 02:50:58 UTC

cvs commit: xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal BindingContextFactoryImpl.java

pcal        2003/12/10 17:50:58

  Modified:    v2/src/xmlpublic/org/apache/xmlbeans
                        BindingContextFactory.java
               v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        BindingContextFactoryImpl.java
  Log:
  make BindingContextFactory tylar-savvy    review zieg
  
  Revision  Changes    Path
  1.2       +15 -0     xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/BindingContextFactory.java
  
  Index: BindingContextFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/BindingContextFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BindingContextFactory.java	14 Nov 2003 00:40:30 -0000	1.1
  +++ BindingContextFactory.java	11 Dec 2003 01:50:58 -0000	1.2
  @@ -60,6 +60,7 @@
   import java.io.File;
   import java.io.IOException;
   import java.io.InputStream;
  +import java.net.URI;
   
   /**
    * BindingContextFactory is used to create BindingContext objects
  @@ -67,6 +68,20 @@
    */
   public abstract class BindingContextFactory
   {
  +  /**
  +   * Creates a BindingContext from a set of tylars located at the given URI.
  +   * The order in which tylars appear in the array determines their precedence
  +   * for loading types.
  +   *
  +   * @param tylarUris An array of URIs which identify the tylars to be used
  +   * in the BindingContext.
  +   * @return The BindingContext
  +   * @throws IOException if a problem occurs while opening or parsing the
  +   * contents of the tylars.
  +   */
  +   public abstract BindingContext createBindingContext(URI[] tylarUris)
  +          throws IOException, XmlException;
  +
       /**
        * Create a BindingContext that only knows about builtin types
        *
  
  
  
  1.4       +59 -8     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BindingContextFactoryImpl.java
  
  Index: BindingContextFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BindingContextFactoryImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BindingContextFactoryImpl.java	5 Dec 2003 23:48:22 -0000	1.3
  +++ BindingContextFactoryImpl.java	11 Dec 2003 01:50:58 -0000	1.4
  @@ -68,11 +68,14 @@
   import org.apache.xmlbeans.impl.binding.bts.PathBindingLoader;
   import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
   import org.apache.xmlbeans.impl.binding.bts.SimpleDocumentBinding;
  +import org.apache.xmlbeans.impl.binding.tylar.Tylar;
  +import org.apache.xmlbeans.impl.binding.tylar.TylarFactory;
   
   import java.io.File;
   import java.io.IOException;
   import java.io.InputStream;
   import java.util.Iterator;
  +import java.net.URI;
   
   /**
    * creates BindingContext objects from various inputs.
  @@ -80,6 +83,40 @@
   public final class BindingContextFactoryImpl
       extends BindingContextFactory
   {
  +
  +  public BindingContext createBindingContext(URI[] tylarUris)
  +          throws IOException, XmlException
  +  {
  +    Tylar[] tylars = new Tylar[tylarUris.length];
  +    for(int i=0; i<tylars.length; i++) {
  +      tylars[i] = TylarFactory.getInstance().load(tylarUris[i]);
  +    }
  +    return createBindingContext(tylars);
  +  }
  +
  +  // REVIEW It's unfortunate that we can't expose this method to the public
  +  // at the moment.  It's easy to imagine cases where one has already built
  +  // up the tylar and doesn't want to pay the cost of re-parsing it.
  +  // Of course, exposing it means we expose Tylar to the public as well,
  +  // and this should be done with caution.
  +  public BindingContext createBindingContext(Tylar[] tylars)
  +  {
  +    // get the binding files
  +    BindingFile[] bfs = new BindingFile[tylars.length];
  +    for(int i=0; i<tylars.length; i++) {
  +      bfs[i] = tylars[i].getBindingFile();
  +    }
  +    // also build the loader chain - this is the binding files plus
  +    // the builtin loader
  +    BindingLoader[] loaders = new BindingLoader[bfs.length+1];
  +    System.arraycopy(bfs,0,loaders,0,bfs.length);
  +    loaders[loaders.length-1] = BuiltinBindingLoader.getInstance();
  +    BindingLoader loader = PathBindingLoader.forPath(loaders);
  +    // finally, glue it all together
  +    RuntimeBindingTypeTable tbl = buildUnmarshallingTypeTable(bfs, loader);
  +    return new BindingContextImpl(loader, tbl);
  +  }
  +
       public BindingContext createBindingContext()
       {
           BindingFile empty = new BindingFile();
  @@ -112,10 +149,10 @@
   
       private static BindingContextImpl createBindingContext(BindingFile bf)
       {
  -        BindingLoader bindingLoader = buildBindingLoader(bf);
  -        RuntimeBindingTypeTable tbl = buildUnmarshallingTypeTable(bf, bindingLoader);
  +      BindingLoader bindingLoader = buildBindingLoader(bf);
  +      RuntimeBindingTypeTable tbl = buildUnmarshallingTypeTable(bf, bindingLoader);
   
  -        return new BindingContextImpl(bindingLoader, tbl);
  +      return new BindingContextImpl(bindingLoader, tbl);
       }
   
       private static BindingLoader buildBindingLoader(BindingFile bf)
  @@ -128,19 +165,33 @@
       private static RuntimeBindingTypeTable buildUnmarshallingTypeTable(BindingFile bf,
                                                                          BindingLoader loader)
       {
  -        RuntimeBindingTypeTable tbl = RuntimeBindingTypeTable.createRuntimeBindingTypeTable();
  +      RuntimeBindingTypeTable tbl = RuntimeBindingTypeTable.createRuntimeBindingTypeTable();
  +      populateTable(bf,loader,tbl);
  +      return tbl;
  +    }
   
  +    private static RuntimeBindingTypeTable buildUnmarshallingTypeTable(BindingFile[] bfs,
  +                                                                       BindingLoader loader)
  +    {
  +      RuntimeBindingTypeTable tbl = RuntimeBindingTypeTable.createRuntimeBindingTypeTable();
  +      for(int i=0; i<bfs.length; i++) populateTable(bfs[i],loader,tbl);
  +      return tbl;
  +    }
  +
  +    private static RuntimeBindingTypeTable populateTable(BindingFile bf,
  +                                                         BindingLoader loader,
  +                                                         RuntimeBindingTypeTable tbl)
  +    {
  +        //TODO scott This may need some more thought; may want to iterate
  +        //through typenames instead of types and resolve them with the loader.
  +        //The loader currently isn't really being used here.
           for (Iterator itr = bf.bindingTypes().iterator(); itr.hasNext();) {
               BindingType type = (BindingType)itr.next();
  -
               if (type instanceof SimpleDocumentBinding) continue;
  -
               TypeUnmarshaller um = createTypeUnmarshaller(type, loader, tbl);
               tbl.putTypeUnmarshaller(type, um);
           }
  -
           tbl.initUnmarshallers(loader);
  -
           return tbl;
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org