On Wed, May 12, 2010 at 4:12 PM, ant elder <[email protected]> wrote:
> Running the assembly compliance tests is slow again now and as a guess
> I'd say its going out on the internet to find some an xsd again. Its
> that what you mean by the comment in here about it being slower? Or is
> this unrelated or unexpected?
>
>   ...ant
>
> On Tue, May 11, 2010 at 7:40 PM,  <[email protected]> wrote:
>> Author: slaws
>> Date: Tue May 11 18:40:54 2010
>> New Revision: 943224
>>
>> URL: http://svn.apache.org/viewvc?rev=943224&view=rev
>> Log:
>> TUSCANY-3553 - add the SCA spec schema to the system contribution so that 
>> users can use SCA schema in property types. I don't know why people would 
>> want to do that but this capability seems to be the intention of the spec. 
>> This slows down the loading of any contributions that use these types, as 
>> the schema are loaded, but has little affect if you don't. I'm still looking 
>> at whether the local scheme optimization I added is effective but decided to 
>> check in as this fault is stopping the otests from running properly 
>> currently.
>>
>> Modified:
>>    tuscany/sca-java-2.x/trunk/modules/deployment/META-INF/MANIFEST.MF
>>    tuscany/sca-java-2.x/trunk/modules/deployment/pom.xml
>>    
>> tuscany/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java
>>    
>> tuscany/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
>>
>> Modified: tuscany/sca-java-2.x/trunk/modules/deployment/META-INF/MANIFEST.MF
>> URL: 
>> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/deployment/META-INF/MANIFEST.MF?rev=943224&r1=943223&r2=943224&view=diff
>> ==============================================================================
>> --- tuscany/sca-java-2.x/trunk/modules/deployment/META-INF/MANIFEST.MF 
>> (original)
>> +++ tuscany/sca-java-2.x/trunk/modules/deployment/META-INF/MANIFEST.MF Tue 
>> May 11 18:40:54 2010
>> @@ -30,6 +30,7 @@ Import-Package: javax.xml.namespace,
>>  javax.xml.stream,
>>  org.apache.tuscany.sca.assembly;version="2.0.0",
>>  org.apache.tuscany.sca.assembly.builder;version="2.0.0",
>> + org.apache.tuscany.sca.assembly.xsd;version="2.0.0",
>>  org.apache.tuscany.sca.common.java.io;version="2.0.0",
>>  org.apache.tuscany.sca.common.xml.stax;version="2.0.0",
>>  org.apache.tuscany.sca.contribution;version="2.0.0",
>> @@ -43,6 +44,7 @@ Import-Package: javax.xml.namespace,
>>  org.apache.tuscany.sca.definitions.xml;version="2.0.0",
>>  org.apache.tuscany.sca.deployment;version="2.0.0",
>>  org.apache.tuscany.sca.monitor;version="2.0.0",
>> + org.apache.tuscany.sca.xsd;version="2.0.0",
>>  org.oasisopen.sca.annotation;version="2.0.0";resolution:=optional
>>  Bundle-SymbolicName: org.apache.tuscany.sca.deployment
>>  Bundle-DocURL: http://www.apache.org/
>>
>> Modified: tuscany/sca-java-2.x/trunk/modules/deployment/pom.xml
>> URL: 
>> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/deployment/pom.xml?rev=943224&r1=943223&r2=943224&view=diff
>> ==============================================================================
>> --- tuscany/sca-java-2.x/trunk/modules/deployment/pom.xml (original)
>> +++ tuscany/sca-java-2.x/trunk/modules/deployment/pom.xml Tue May 11 
>> 18:40:54 2010
>> @@ -52,16 +52,21 @@
>>
>>         <dependency>
>>             <groupId>org.apache.tuscany.sca</groupId>
>> -            <artifactId>tuscany-builder</artifactId>
>> +            <artifactId>tuscany-assembly-xsd</artifactId>
>>             <version>2.0-SNAPSHOT</version>
>> -            <scope>runtime</scope>
>> -        </dependency>
>> +        </dependency>
>>
>>         <dependency>
>>             <groupId>org.apache.tuscany.sca</groupId>
>> -            <artifactId>tuscany-assembly-xsd</artifactId>
>> +            <artifactId>tuscany-xsd</artifactId>
>>             <version>2.0-SNAPSHOT</version>
>> -            <scope>test</scope>
>> +        </dependency>
>> +
>> +        <dependency>
>> +            <groupId>org.apache.tuscany.sca</groupId>
>> +            <artifactId>tuscany-builder</artifactId>
>> +            <version>2.0-SNAPSHOT</version>
>> +            <scope>runtime</scope>
>>         </dependency>
>>
>>        <dependency>
>> @@ -69,7 +74,9 @@
>>             <artifactId>tuscany-implementation-java</artifactId>
>>             <version>2.0-SNAPSHOT</version>
>>             <scope>test</scope>
>> -        </dependency>
>> +        </dependency>
>> +
>> +
>>
>>     </dependencies>
>>
>>
>> Modified: 
>> tuscany/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java
>> URL: 
>> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java?rev=943224&r1=943223&r2=943224&view=diff
>> ==============================================================================
>> --- 
>> tuscany/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java
>>  (original)
>> +++ 
>> tuscany/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java
>>  Tue May 11 18:40:54 2010
>> @@ -43,6 +43,7 @@ import org.apache.tuscany.sca.assembly.b
>>  import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint;
>>  import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
>>  import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
>> +import org.apache.tuscany.sca.assembly.xsd.Constants;
>>  import org.apache.tuscany.sca.common.xml.stax.StAXHelper;
>>  import org.apache.tuscany.sca.contribution.Artifact;
>>  import org.apache.tuscany.sca.contribution.Contribution;
>> @@ -77,6 +78,8 @@ import org.apache.tuscany.sca.definition
>>  import org.apache.tuscany.sca.deployment.Deployer;
>>  import org.apache.tuscany.sca.monitor.Monitor;
>>  import org.apache.tuscany.sca.monitor.MonitorFactory;
>> +import org.apache.tuscany.sca.xsd.XSDFactory;
>> +import org.apache.tuscany.sca.xsd.XSDefinition;
>>
>>  /**
>>  *
>> @@ -98,11 +101,14 @@ public class DeployerImpl implements Dep
>>     protected Definitions systemDefinitions;
>>     protected ExtensibleURLArtifactProcessor artifactProcessor;
>>     protected ExtensibleStAXArtifactProcessor staxProcessor;
>> +    protected ValidationSchemaExtensionPoint validationSchema;
>>
>>     protected MonitorFactory monitorFactory;
>>
>>     protected static final String DEPLOYER_IMPL_VALIDATION_MESSAGES =
>>         
>> "org.apache.tuscany.sca.deployment.impl.deployer-impl-validation-messages";
>> +
>> +    public static final QName XSD = new 
>> QName("http://www.w3.org/2001/XMLSchema";, "schema");
>>
>>     /**
>>      * @param registry
>> @@ -301,6 +307,9 @@ public class DeployerImpl implements Dep
>>         compositeBuilder =
>>             
>> compositeBuilders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder");
>>
>> +        // get the validation schema
>> +        validationSchema = 
>> registry.getExtensionPoint(ValidationSchemaExtensionPoint.class);
>> +
>>         loadSystemContribution(new 
>> ProcessorContext(monitorFactory.createMonitor()));
>>
>>         inited = true;
>> @@ -341,7 +350,7 @@ public class DeployerImpl implements Dep
>>         artifact.setLocation("Derived");
>>         artifact.setModel(systemDefinitions);
>>         artifacts.add(artifact);
>> -
>> +
>>         // now resolve and add the system contribution
>>         try {
>>             contributionProcessor.resolve(systemContribution, modelResolver, 
>> context);
>> @@ -355,6 +364,7 @@ public class DeployerImpl implements Dep
>>         Contribution contribution = contributionFactory.createContribution();
>>         contribution.setURI(systemContribution.getURI());
>>         contribution.setLocation(systemContribution.getLocation());
>> +
>>         ModelResolver modelResolver = new 
>> ExtensibleModelResolver(contribution, modelResolvers, modelFactories);
>>         contribution.setModelResolver(modelResolver);
>>         contribution.setUnresolved(true);
>> @@ -362,6 +372,7 @@ public class DeployerImpl implements Dep
>>         DefinitionsFactory definitionsFactory = 
>> modelFactories.getFactory(DefinitionsFactory.class);
>>         Definitions definitions = definitionsFactory.createDefinitions();
>>         DefinitionsUtil.aggregate(systemDefinitions, definitions, monitor);
>> +
>>         // create an artifact to represent the system defintions and
>>         // add it to the contribution
>>         List<Artifact> artifacts = contribution.getArtifacts();
>> @@ -370,6 +381,44 @@ public class DeployerImpl implements Dep
>>         artifact.setLocation("Derived");
>>         artifact.setModel(definitions);
>>         artifacts.add(artifact);
>> +
>> +        // create resolver entries to represent the SCA schema. We don't 
>> create artifacts
>> +        // in the contribution as the XSD schema are only actually loaded 
>> on demand
>> +        // so as long as they are in the model resolver we are set. We do 
>> it on the clone
>> +        // so that every copy of the system contribution has the schema
>> +        ProcessorContext context = new ProcessorContext(monitor);
>> +        XSDFactory xsdFactory = modelFactories.getFactory(XSDFactory.class);
>> +        List<String> scaSchemas = validationSchema.getSchemas();
>> +        for (String scaSchemaLocation : scaSchemas){
>> +            try {
>> +                URL scaSchemaURL = new URL(scaSchemaLocation);
>> +                String namespace = staxHelper.readAttribute(scaSchemaURL, 
>> XSD, "targetNamespace");
>> +
>> +                // if this is the SCA schema store it in the system 
>> contribution
>> +                if (namespace.equals(Constants.SCA11_TUSCANY_NS)){
>> +
>> +                    // add the schema to the model resolver under the 
>> Tuscany namespace
>> +                    XSDefinition scaSchema = 
>> xsdFactory.createXSDefinition();
>> +                    scaSchema.setUnresolved(true);
>> +                    scaSchema.setNamespace(namespace);
>> +                    scaSchema.setLocation(scaSchemaURL.toURI());
>> +                    scaSchema.setUnresolved(false);
>> +//                    modelResolver.addModel(scaSchema, context);
>> +
>> +                    // we know that the SCA schema's are referenced form 
>> the Tuscany schemas so
>> +                    // register the schema under the SCA namsepace too
>> +                    scaSchema = xsdFactory.createXSDefinition();
>> +                    scaSchema.setUnresolved(true);
>> +                    scaSchema.setNamespace(Constants.SCA11_NS);
>> +                    scaSchema.setLocation(scaSchemaURL.toURI());
>> +                    scaSchema.setUnresolved(false);
>> +                    modelResolver.addModel(scaSchema, context);
>> +                }
>> +            } catch (Exception ex) {
>> +                throw new IllegalStateException(ex);
>> +            }
>> +        }
>> +
>>         return contribution;
>>     }
>>
>>
>> Modified: 
>> tuscany/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
>> URL: 
>> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java?rev=943224&r1=943223&r2=943224&view=diff
>> ==============================================================================
>> --- 
>> tuscany/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
>>  (original)
>> +++ 
>> tuscany/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
>>  Tue May 11 18:40:54 2010
>> @@ -29,6 +29,7 @@ import java.util.HashMap;
>>  import java.util.List;
>>  import java.util.Map;
>>
>> +import org.apache.tuscany.sca.assembly.xsd.Constants;
>>  import org.apache.tuscany.sca.common.xml.XMLDocumentHelper;
>>  import org.apache.tuscany.sca.contribution.Artifact;
>>  import org.apache.tuscany.sca.contribution.Contribution;
>> @@ -365,7 +366,14 @@ public class XSDModelResolver implements
>>                         return new InputSource(schemaLocation);
>>                     }
>>                 } else {
>> -                    url = new URL(new URL(baseUri), schemaLocation);
>> +                    // look to see whether Tuscany has a local version of 
>> the
>> +                    // required schema. It can load the local version rather
>> +                    // than going out to the network in order to improve 
>> performance
>> +                    url = Constants.CACHED_XSDS.get(targetNamespace);
>> +
>> +                    if (url == null) {
>> +                        url = new URL(new URL(baseUri), schemaLocation);
>> +                    }
>>                 }
>>                 return XMLDocumentHelper.getInputSource(url);
>>             } catch (IOException e) {
>>
>>
>>
>

As per commit comment I believe that the local read optimization isn't
working and that it is going out to the internet for external schemas.
Still haven't got to the bottom of it yet.

Simon


-- 
Apache Tuscany committer: tuscany.apache.org
Co-author of a book about Tuscany and SCA: tuscanyinaction.com

Reply via email to