diff options
Diffstat (limited to 'branches')
21 files changed, 608 insertions, 547 deletions
diff --git a/branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java b/branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java index b6b805e383..00df45a49e 100644 --- a/branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java +++ b/branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingProviderFactory.java @@ -6,15 +6,15 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.binding.atom.provider; @@ -22,10 +22,8 @@ package org.apache.tuscany.sca.binding.atom.provider; import org.apache.tuscany.sca.binding.atom.AtomBinding; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.databinding.Mediator; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; import org.apache.tuscany.sca.invocation.MessageFactory; @@ -52,8 +50,7 @@ public class AtomBindingProviderFactory implements BindingProviderFactory<AtomBi this.servletHost = servletHosts.getServletHosts().get(0); ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); this.messageFactory = modelFactories.getFactory(MessageFactory.class); - this.mediator = new MediatorImpl(extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class), - extensionPoints.getExtensionPoint(TransformerExtensionPoint.class)); + this.mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); } public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, diff --git a/branches/sca-java-1.x/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.java b/branches/sca-java-1.x/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.java index 9a858f899f..6e134fd0c2 100644 --- a/branches/sca-java-1.x/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.java +++ b/branches/sca-java-1.x/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.java @@ -6,15 +6,15 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.binding.feed.provider; @@ -22,10 +22,8 @@ package org.apache.tuscany.sca.binding.feed.provider; import org.apache.tuscany.sca.binding.feed.AtomBinding; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.databinding.Mediator; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; import org.apache.tuscany.sca.invocation.MessageFactory; @@ -52,8 +50,7 @@ public class AtomBindingProviderFactory implements BindingProviderFactory<AtomBi this.servletHost = servletHosts.getServletHosts().get(0); ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); this.messageFactory = modelFactories.getFactory(MessageFactory.class); - this.mediator = new MediatorImpl(extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class), - extensionPoints.getExtensionPoint(TransformerExtensionPoint.class)); + this.mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); } public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, diff --git a/branches/sca-java-1.x/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.java b/branches/sca-java-1.x/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.java index f4c336e12b..649af78c5b 100644 --- a/branches/sca-java-1.x/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.java +++ b/branches/sca-java-1.x/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.java @@ -6,15 +6,15 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.binding.feed.provider; @@ -22,10 +22,8 @@ package org.apache.tuscany.sca.binding.feed.provider; import org.apache.tuscany.sca.binding.feed.RSSBinding; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.databinding.Mediator; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; import org.apache.tuscany.sca.invocation.MessageFactory; @@ -52,8 +50,7 @@ public class RSSBindingProviderFactory implements BindingProviderFactory<RSSBind this.servletHost = servletHosts.getServletHosts().get(0); ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); this.messageFactory = modelFactories.getFactory(MessageFactory.class); - this.mediator = new MediatorImpl(extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class), - extensionPoints.getExtensionPoint(TransformerExtensionPoint.class)); + this.mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); } public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, diff --git a/branches/sca-java-1.x/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingProviderFactory.java b/branches/sca-java-1.x/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingProviderFactory.java index 9be7ba6392..62a05e91d0 100644 --- a/branches/sca-java-1.x/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingProviderFactory.java +++ b/branches/sca-java-1.x/modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingProviderFactory.java @@ -6,15 +6,15 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.binding.gdata.provider; @@ -22,10 +22,8 @@ package org.apache.tuscany.sca.binding.gdata.provider; import org.apache.tuscany.sca.binding.gdata.GdataBinding; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.databinding.Mediator; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; import org.apache.tuscany.sca.invocation.MessageFactory; @@ -40,7 +38,7 @@ import com.google.gdata.util.AuthenticationException; /** * Implementation of a Binding provider factory for the Atom binding. - * + * * @version $Rev$ $Date$ */ public class GdataBindingProviderFactory implements BindingProviderFactory<GdataBinding> { @@ -54,9 +52,7 @@ public class GdataBindingProviderFactory implements BindingProviderFactory<Gdata this.servletHost = servletHosts.getServletHosts().get(0); ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); this.messageFactory = modelFactories.getFactory(MessageFactory.class); - this.mediator = - new MediatorImpl(extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class), extensionPoints - .getExtensionPoint(TransformerExtensionPoint.class)); + this.mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); } public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, @@ -68,7 +64,7 @@ public class GdataBindingProviderFactory implements BindingProviderFactory<Gdata e.printStackTrace(); return null; //Google authentication error! : This exception needs to be handled into a better way } - + } public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, diff --git a/branches/sca-java-1.x/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingProviderFactory.java b/branches/sca-java-1.x/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingProviderFactory.java index b9cababcab..d588f041db 100644 --- a/branches/sca-java-1.x/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingProviderFactory.java +++ b/branches/sca-java-1.x/modules/binding-rss-rome/src/main/java/org/apache/tuscany/sca/binding/rss/provider/RSSBindingProviderFactory.java @@ -6,15 +6,15 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.binding.rss.provider; @@ -22,10 +22,8 @@ package org.apache.tuscany.sca.binding.rss.provider; import org.apache.tuscany.sca.binding.rss.RSSBinding; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.databinding.Mediator; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; import org.apache.tuscany.sca.invocation.MessageFactory; @@ -52,8 +50,7 @@ public class RSSBindingProviderFactory implements BindingProviderFactory<RSSBind this.servletHost = servletHosts.getServletHosts().get(0); ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); this.messageFactory = modelFactories.getFactory(MessageFactory.class); - this.mediator = new MediatorImpl(extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class), - extensionPoints.getExtensionPoint(TransformerExtensionPoint.class)); + this.mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); } public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, diff --git a/branches/sca-java-1.x/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java b/branches/sca-java-1.x/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java index 32d8cf5b74..bb5cdda4fc 100644 --- a/branches/sca-java-1.x/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java +++ b/branches/sca-java-1.x/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java @@ -6,15 +6,15 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.contribution.service.impl; @@ -25,7 +25,6 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.net.URLClassLoader; import java.net.URLConnection; import java.security.AccessController; import java.security.PrivilegedAction; @@ -57,7 +56,6 @@ import org.apache.tuscany.sca.contribution.service.ContributionService; import org.apache.tuscany.sca.contribution.service.ExtensibleContributionListener; import org.apache.tuscany.sca.contribution.service.TypeDescriber; import org.apache.tuscany.sca.contribution.service.util.IOHelper; -import org.apache.tuscany.sca.contribution.xml.ContributionMetadataDocumentProcessor; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.SCADefinitions; import org.apache.tuscany.sca.monitor.Monitor; @@ -69,7 +67,7 @@ import org.apache.tuscany.sca.policy.PolicySet; /** * Service interface that manages artifacts contributed to a Tuscany runtime. - * + * * @version $Rev$ $Date$ */ public class ContributionServiceImpl implements ContributionService { @@ -128,16 +126,16 @@ public class ContributionServiceImpl implements ContributionService { * Contribution model factory */ private ContributionFactory contributionFactory; - - + + private ModelResolver policyDefinitionsResolver; - private List policyDefinitions; - + private List policyDefinitions; + private Monitor monitor; - - private String COMPOSITE_FILE_EXTN = ".composite"; - + + private String COMPOSITE_FILE_EXTN = ".composite"; + private TypeDescriber packageTypeDescriber; public ContributionServiceImpl(ContributionRepository repository, @@ -152,7 +150,7 @@ public class ContributionServiceImpl implements ContributionService { ContributionFactory contributionFactory, XMLInputFactory xmlFactory, List<SCADefinitions> policyDefinitions, - ExtensionPointRegistry extensionPoints, + ExtensionPointRegistry extensionPoints, Monitor monitor) { super(); this.extensionPoints = extensionPoints; @@ -169,13 +167,13 @@ public class ContributionServiceImpl implements ContributionService { this.policyDefinitionsResolver = policyDefinitionsResolver; this.policyDefinitions = policyDefinitions; this.monitor = monitor; - + this.packageTypeDescriber = new PackageTypeDescriberImpl(); } - + /** * Report a error. - * + * * @param problems * @param message * @param model @@ -261,24 +259,25 @@ public class ContributionServiceImpl implements ContributionService { /** * Perform read of the contribution metadata loader (sca-contribution.xml and sca-contribution-generated.xml) * When the two metadata files are available, the information provided are merged, and the sca-contribution has priorities - * + * * @param sourceURL * @return Contribution * @throws ContributionException */ + /* private Contribution readContributionMetadata(URL sourceURL) throws ContributionException { Contribution contributionMetadata = contributionFactory.createContribution(); ContributionMetadataDocumentProcessor metadataDocumentProcessor = new ContributionMetadataDocumentProcessor(modelFactories, staxProcessor, monitor); - + final URL[] urls = {sourceURL}; // Allow access to create classloader. Requires RuntimePermission in security policy. URLClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { return new URLClassLoader(urls, null); } - }); + }); for (String path: new String[]{ Contribution.SCA_CONTRIBUTION_GENERATED_META, Contribution.SCA_CONTRIBUTION_META}) { @@ -290,7 +289,7 @@ public class ContributionServiceImpl implements ContributionService { contributionMetadata.getDeployables().addAll(contribution.getDeployables()); } } - + // For debugging purposes, write it back to XML // if (contributionMetadata != null) { // try { @@ -311,7 +310,8 @@ public class ContributionServiceImpl implements ContributionService { return contributionMetadata; } - + */ + private static boolean isDirectory(URL url) { if ("file".equals(url.getProtocol())) { try { @@ -322,7 +322,7 @@ public class ContributionServiceImpl implements ContributionService { } }); } catch (URISyntaxException e) { - // Ignore + // Ignore } } return false; @@ -330,13 +330,13 @@ public class ContributionServiceImpl implements ContributionService { /** * Note: - * + * * @param contributionURI ContributionID * @param sourceURL contribution location * @param contributionStream contribution content * @param storeInRepository flag if we store the contribution into the * repository or not - * @return the contribution model representing the contribution + * @return the contribution model representing the contribution * @throws IOException * @throws DeploymentException */ @@ -361,8 +361,7 @@ public class ContributionServiceImpl implements ContributionService { } } - //initialize contribution based on it's metadata if available - Contribution contribution = readContributionMetadata(locationURL); + Contribution contribution = contributionFactory.createContribution(); // Create contribution model resolver if (modelResolver == null) { @@ -376,7 +375,7 @@ public class ContributionServiceImpl implements ContributionService { contribution.setLocation(locationURL.toString()); contribution.setModelResolver(modelResolver); contribution.setType(packageTypeDescriber.getType(locationURL, null)); - + List<URI> contributionArtifacts = null; //NOTE: if a contribution is stored on the repository @@ -400,7 +399,7 @@ public class ContributionServiceImpl implements ContributionService { throw (IOException)e.getException(); } } - + try { // process the contribution contributionArtifacts = this.packageProcessor.getArtifacts(locationURL, contributionStream); @@ -412,7 +411,7 @@ public class ContributionServiceImpl implements ContributionService { // process the contribution contributionArtifacts = this.packageProcessor.getArtifacts(locationURL, contributionStream); } - + // Read all artifacts in the contribution try { // Allow access to read system properties. Requires PropertyPermission in security policy. @@ -422,6 +421,8 @@ public class ContributionServiceImpl implements ContributionService { throw new ContributionException(e); } + readContributionMetadata(contribution); + // this.contributionListener.contributionAdded(this.contributionRepository, contribution); @@ -450,12 +451,34 @@ public class ContributionServiceImpl implements ContributionService { return contribution; } + private void readContributionMetadata(Contribution contribution) { + ContributionMetadata m1 = null, m2 = null; + for(Artifact a: contribution.getArtifacts()) { + if(Contribution.SCA_CONTRIBUTION_GENERATED_META.equals(a.getURI())) { + m1 = (ContributionMetadata) a.getModel(); + } + if(Contribution.SCA_CONTRIBUTION_META.equals(a.getURI())) { + m2 = (ContributionMetadata) a.getModel(); + } + } + if (m1 != null) { + contribution.getImports().addAll(m1.getImports()); + contribution.getExports().addAll(m1.getExports()); + contribution.getDeployables().addAll(m1.getDeployables()); + } + if (m2 != null) { + contribution.getImports().addAll(m2.getImports()); + contribution.getExports().addAll(m2.getExports()); + contribution.getDeployables().addAll(m2.getDeployables()); + } + } + /** - * Process any application composite (eg see 5.1.3 of SCA JEE spec) + * Process any application composite (eg see 5.1.3 of SCA JEE spec) * TODO: see TUSCANY-2581 */ private void processApplicationComposite(Contribution contribution) { - + Composite composite = findComposite("web-inf/web.composite", contribution); if (composite != null) { if (!contribution.getDeployables().contains(composite)) { @@ -485,9 +508,9 @@ public class ContributionServiceImpl implements ContributionService { } /** - * This utility method process each artifact and delegates to proper + * This utility method process each artifact and delegates to proper * artifactProcessor to read the model and generate the in-memory representation - * + * * @param contribution * @param artifacts * @throws ContributionException @@ -498,9 +521,9 @@ public class ContributionServiceImpl implements ContributionService { ModelResolver modelResolver = contribution.getModelResolver(); URL contributionURL = new URL(contribution.getLocation()); - + List<URI> compositeUris = new ArrayList<URI>(); - + Object model = null; for (URI anArtifactUri : artifacts) { if ( anArtifactUri.toString().endsWith(COMPOSITE_FILE_EXTN)) { @@ -514,32 +537,32 @@ public class ContributionServiceImpl implements ContributionService { artifact.setLocation(artifactURL.toString()); contribution.getArtifacts().add(artifact); modelResolver.addModel(artifact); - + model = this.artifactProcessor.read(contributionURL, anArtifactUri, artifactURL); - + if (model != null) { artifact.setModel(model); // Add the loaded model to the model resolver modelResolver.addModel(model); - + // Add policy definitions to the list of policy definitions - if (model instanceof SCADefinitions) { + if (model instanceof SCADefinitions) { policyDefinitions.add(model); - + SCADefinitions definitions = (SCADefinitions)model; for (Intent intent : definitions.getPolicyIntents() ) { policyDefinitionsResolver.addModel(intent); } - + for (PolicySet policySet : definitions.getPolicySets() ) { policyDefinitionsResolver.addModel(policySet); } - + for (IntentAttachPointType attachPointType : definitions.getBindingTypes() ) { policyDefinitionsResolver.addModel(attachPointType); } - + for (IntentAttachPointType attachPointType : definitions.getImplementationTypes() ) { policyDefinitionsResolver.addModel(attachPointType); } @@ -550,7 +573,7 @@ public class ContributionServiceImpl implements ContributionService { } } } - + for (URI anArtifactUri : compositeUris) { URL artifactURL = packageProcessor.getArtifactURL(new URL(contribution.getLocation()), anArtifactUri); @@ -560,7 +583,7 @@ public class ContributionServiceImpl implements ContributionService { artifact.setLocation(artifactURL.toString()); contribution.getArtifacts().add(artifact); modelResolver.addModel(artifact); - + model = this.artifactProcessor.read(contributionURL, anArtifactUri, artifactURL); if (model != null) { artifact.setModel(model); @@ -571,9 +594,9 @@ public class ContributionServiceImpl implements ContributionService { } /** - * This utility method process each artifact and delegates to proper + * This utility method process each artifact and delegates to proper * artifactProcessor to resolve the model references - * + * * @param contribution * @throws ContributionException */ diff --git a/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java b/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java index 19e05d4df9..9e926506f4 100644 --- a/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java +++ b/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java @@ -6,22 +6,24 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.core.databinding.module; +import org.apache.axiom.om.OMElement; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.databinding.processor.DataBindingJavaInterfaceProcessor; import org.apache.tuscany.sca.core.databinding.processor.WrapperJavaInterfaceProcessor; import org.apache.tuscany.sca.core.databinding.transformers.Array2ArrayTransformer; @@ -30,14 +32,14 @@ import org.apache.tuscany.sca.core.databinding.transformers.CallableReferenceDat import org.apache.tuscany.sca.core.databinding.transformers.CallableReferenceXMLAdapter; import org.apache.tuscany.sca.core.databinding.transformers.Exception2ExceptionTransformer; import org.apache.tuscany.sca.core.databinding.transformers.Input2InputTransformer; +import org.apache.tuscany.sca.core.databinding.transformers.OMElementXMLAdapter; import org.apache.tuscany.sca.core.databinding.transformers.Output2OutputTransformer; import org.apache.tuscany.sca.core.databinding.transformers.XMLStreamReader2CallableReference; -import org.apache.tuscany.sca.core.databinding.transformers.OMElementXMLAdapter; import org.apache.tuscany.sca.core.databinding.wire.DataBindingRuntimeWireProcessor; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; import org.apache.tuscany.sca.databinding.impl.Group2GroupTransformer; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; import org.apache.tuscany.sca.databinding.jaxb.XMLAdapterExtensionPoint; import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; @@ -46,7 +48,6 @@ import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcesso import org.apache.tuscany.sca.interfacedef.java.jaxws.WebServiceInterfaceProcessor; import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; import org.osoa.sca.CallableReference; -import org.apache.axiom.om.OMElement; /** * @version $Rev$ $Date$ @@ -61,8 +62,9 @@ public class DataBindingModuleActivator implements ModuleActivator { xmlAdapterExtensionPoint.addAdapter(CallableReference.class, CallableReferenceXMLAdapter.class); xmlAdapterExtensionPoint.addAdapter(OMElement.class, OMElementXMLAdapter.class); FaultExceptionMapper faultExceptionMapper = new JAXWSFaultExceptionMapper(dataBindings, xmlAdapterExtensionPoint); - - MediatorImpl mediator = new MediatorImpl(dataBindings, transformers); + + Mediator mediator = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); + Input2InputTransformer input2InputTransformer = new Input2InputTransformer(); input2InputTransformer.setMediator(mediator); transformers.addTransformer(input2InputTransformer, true); @@ -73,7 +75,7 @@ public class DataBindingModuleActivator implements ModuleActivator { Exception2ExceptionTransformer exception2ExceptionTransformer = new Exception2ExceptionTransformer(mediator, faultExceptionMapper); transformers.addTransformer(exception2ExceptionTransformer, false); - + Array2ArrayTransformer array2ArrayTransformer = new Array2ArrayTransformer(); array2ArrayTransformer.setMediator(mediator); transformers.addTransformer(array2ArrayTransformer, true); @@ -81,14 +83,14 @@ public class DataBindingModuleActivator implements ModuleActivator { Group2GroupTransformer group2GroupTransformer = new Group2GroupTransformer(); group2GroupTransformer.setMediator(mediator); transformers.addTransformer(group2GroupTransformer, true); - + dataBindings.addDataBinding(new CallableReferenceDataBinding()); transformers.addTransformer(new CallableReference2XMLStreamReader(), true); transformers.addTransformer(new XMLStreamReader2CallableReference(), false); ModelFactoryExtensionPoint modelFactories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); - // Add the WebServiceInterfaceProcessor to mark the interface remotable + // Add the WebServiceInterfaceProcessor to mark the interface remotable javaFactory.addInterfaceVisitor(new WebServiceInterfaceProcessor()); // Introspect the data types javaFactory.addInterfaceVisitor(new DataBindingJavaInterfaceProcessor(dataBindings)); @@ -100,7 +102,7 @@ public class DataBindingModuleActivator implements ModuleActivator { if (wireProcessorExtensionPoint != null) { wireProcessorExtensionPoint.addWireProcessor(new DataBindingRuntimeWireProcessor(mediator, dataBindings, faultExceptionMapper)); } - + } public void stop(ExtensionPointRegistry registry) { diff --git a/branches/sca-java-1.x/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java b/branches/sca-java-1.x/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java index e0860ff395..b12d727ba9 100644 --- a/branches/sca-java-1.x/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java +++ b/branches/sca-java-1.x/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java @@ -6,15 +6,15 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.databinding; @@ -28,6 +28,7 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; import org.apache.tuscany.sca.databinding.javabeans.JavaExceptionDataBinding; import org.apache.tuscany.sca.extensibility.ServiceDeclaration; @@ -39,10 +40,11 @@ import org.apache.tuscany.sca.interfacedef.util.XMLType; /** * The default implementation of a data binding extension point. - * + * * @version $Rev$ $Date$ */ public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoint { + private ExtensionPointRegistry registry; private final Map<String, DataBinding> bindings = new HashMap<String, DataBinding>(); private final List<DataBinding> databindings = new ArrayList<DataBinding>(); private static final Logger logger = Logger.getLogger(DefaultDataBindingExtensionPoint.class.getName()); @@ -51,6 +53,10 @@ public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoi public DefaultDataBindingExtensionPoint() { } + public DefaultDataBindingExtensionPoint(ExtensionPointRegistry registry) { + this.registry = registry; + } + public DataBinding getDataBinding(String id) { if (id == null) { return null; @@ -121,7 +127,7 @@ public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoi * A data binding facade allowing data bindings to be lazily loaded and * initialized. */ - private static class LazyDataBinding implements DataBinding { + private class LazyDataBinding implements DataBinding { private String name; private ServiceDeclaration dataBindingDeclaration; @@ -134,7 +140,7 @@ public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoi /** * Load and instantiate the data binding class. - * + * * @return The data binding. */ @SuppressWarnings("unchecked") @@ -142,8 +148,14 @@ public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoi if (dataBinding == null) { try { Class<DataBinding> dataBindingClass = (Class<DataBinding>)dataBindingDeclaration.loadClass(); - Constructor<DataBinding> constructor = dataBindingClass.getConstructor(); - dataBinding = constructor.newInstance(); + try { + Constructor<DataBinding> constructor = dataBindingClass.getConstructor(); + dataBinding = constructor.newInstance(); + } catch (NoSuchMethodException e) { + Constructor<DataBinding> constructor = + dataBindingClass.getConstructor(ExtensionPointRegistry.class); + dataBinding = constructor.newInstance(DefaultDataBindingExtensionPoint.this.registry); + } } catch (Exception e) { throw new IllegalStateException(e); } diff --git a/branches/sca-java-1.x/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java b/branches/sca-java-1.x/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java index b7ddf87a41..08d7301f02 100644 --- a/branches/sca-java-1.x/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java +++ b/branches/sca-java-1.x/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java @@ -6,23 +6,25 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.databinding.impl; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; import org.apache.tuscany.sca.databinding.DataPipe; import org.apache.tuscany.sca.databinding.DataPipeTransformer; @@ -43,15 +45,21 @@ import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; * @version $Rev$ $Date$ */ public class MediatorImpl implements Mediator { - + private ExtensionPointRegistry registry; private DataBindingExtensionPoint dataBindings; private TransformerExtensionPoint transformers; - public MediatorImpl(DataBindingExtensionPoint dataBindings, TransformerExtensionPoint transformers) { + MediatorImpl(DataBindingExtensionPoint dataBindings, TransformerExtensionPoint transformers) { this.dataBindings = dataBindings; this.transformers = transformers; } + public MediatorImpl(ExtensionPointRegistry registry) { + this.registry = registry; + this.dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); + this.transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); + } + @SuppressWarnings("unchecked") public Object mediate(Object source, DataType sourceDataType, DataType targetDataType, Map<String, Object> metadata) { if (sourceDataType == null || sourceDataType.getDataBinding() == null) { @@ -103,7 +111,7 @@ public class MediatorImpl implements Mediator { DataType targetType = (index == size - 1) ? targetDataType : new DataTypeImpl<Object>(transformer.getTargetDataBinding(), Object.class, targetDataType.getLogical()); - + //FIXME The ClassLoader should be passed in // Allow privileged access to get ClassLoader. Requires RuntimePermission in security // policy. @@ -111,9 +119,15 @@ public class MediatorImpl implements Mediator { public ClassLoader run() { return Thread.currentThread().getContextClassLoader(); } - }); - - TransformationContext context = new TransformationContextImpl(sourceType, targetType, classLoader, metadata); + }); + + Map<String, Object> copy = new HashMap<String, Object>(); + if (metadata != null) { + copy.putAll(metadata); + } + copy.put(ExtensionPointRegistry.class.getName(), registry); + + TransformationContext context = new TransformationContextImpl(sourceType, targetType, classLoader, copy); return context; } diff --git a/branches/sca-java-1.x/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.Mediator b/branches/sca-java-1.x/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.Mediator new file mode 100644 index 0000000000..e01e121aa5 --- /dev/null +++ b/branches/sca-java-1.x/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.Mediator @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+org.apache.tuscany.sca.databinding.impl.MediatorImpl
\ No newline at end of file diff --git a/branches/sca-java-1.x/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/ImplementationsActivator.java b/branches/sca-java-1.x/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/ImplementationsActivator.java index d156d835ad..a861a8ddf0 100644 --- a/branches/sca-java-1.x/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/ImplementationsActivator.java +++ b/branches/sca-java-1.x/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/ImplementationsActivator.java @@ -6,15 +6,15 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.extension.helper.impl; @@ -31,9 +31,8 @@ import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.ModuleActivator; -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; import org.apache.tuscany.sca.extension.helper.ImplementationActivator; import org.apache.tuscany.sca.extension.helper.utils.DefaultPropertyValueObjectFactory; import org.apache.tuscany.sca.extension.helper.utils.PropertyValueObjectFactory; @@ -50,16 +49,14 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent; public class ImplementationsActivator implements ModuleActivator { protected List<ImplementationActivator> implementationActivators; - + public void start(ExtensionPointRegistry registry) { ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class); - DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); - TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); - MediatorImpl mediator = new MediatorImpl(dataBindings, transformers); - + Mediator mediator = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); + //FIXME Pass this factory differently as it's not an extension point PropertyValueObjectFactory propertyFactory = new DefaultPropertyValueObjectFactory(mediator); registry.addExtensionPoint(propertyFactory); diff --git a/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java b/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java index 695dea3343..eefe82f1d9 100644 --- a/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java +++ b/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java @@ -6,15 +6,15 @@ * to you 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.
+ * under the License.
*/
package org.apache.tuscany.sca.implementation.java.injection;
@@ -26,6 +26,8 @@ import java.util.StringTokenizer; import org.apache.tuscany.sca.assembly.ComponentProperty;
import org.apache.tuscany.sca.assembly.Property;
import org.apache.tuscany.sca.context.PropertyValueFactory;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.core.factory.ObjectCreationException;
import org.apache.tuscany.sca.core.factory.ObjectFactory;
import org.apache.tuscany.sca.databinding.Mediator;
@@ -55,7 +57,11 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory { public JavaPropertyValueObjectFactory(Mediator mediator) {
this.mediator = mediator;
}
-
+
+ public JavaPropertyValueObjectFactory(ExtensionPointRegistry registry) {
+ this.mediator = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class);
+ }
+
public ObjectFactory createValueFactory(Property property, Object propertyValue, JavaElementImpl javaElement) {
isSimpleType = isSimpleType(property);
Document doc = (Document)propertyValue;
@@ -131,7 +137,7 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory { }
}
- }
+ }
private boolean isSimpleType(Property property) {
if (property.getXSDType() != null) {
@@ -227,10 +233,10 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory { try {
return simpleTypeMapper.toJavaObject(property.getXSDType(), (String)propertyValue, null);
} catch (NumberFormatException ex) {
- throw new ObjectCreationException("Failed to create instance for property "
+ throw new ObjectCreationException("Failed to create instance for property "
+ property.getName() + " with value " + propertyValue, ex);
} catch (IllegalArgumentException ex) {
- throw new ObjectCreationException("Failed to create instance for property "
+ throw new ObjectCreationException("Failed to create instance for property "
+ property.getName() + " with value " + propertyValue, ex);
}
} else {
@@ -253,12 +259,12 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory { try {
values.add(simpleTypeMapper.toJavaObject(property.getXSDType(), aValue, null));
} catch (NumberFormatException ex) {
- throw new ObjectCreationException("Failed to create instance for property "
- + property.getName() + " with value " + aValue
+ throw new ObjectCreationException("Failed to create instance for property "
+ + property.getName() + " with value " + aValue
+ " from value list of " + propertyValue, ex);
} catch (IllegalArgumentException ex) {
- throw new ObjectCreationException("Failed to create instance for property "
- + property.getName() + " with value " + aValue
+ throw new ObjectCreationException("Failed to create instance for property "
+ + property.getName() + " with value " + aValue
+ " from value list of " + propertyValue, ex);
}
}
@@ -272,7 +278,7 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory { }
}
}
-
+
public class ArrayObjectFactoryImpl extends ObjectFactoryImplBase {
public ArrayObjectFactoryImpl(Property property, List<?> propertyValues, boolean isSimpleType, Class javaType) {
super(property, propertyValues, isSimpleType, javaType);
@@ -287,11 +293,11 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory { try {
Array.set(values, count++, simpleTypeMapper.toJavaObject(property.getXSDType(), aValue, null));
} catch (NumberFormatException ex) {
- throw new ObjectCreationException("Failed to create instance for property "
+ throw new ObjectCreationException("Failed to create instance for property "
+ property.getName() + " with value " + aValue
+ " from value list of " + propertyValue, ex);
} catch (IllegalArgumentException ex) {
- throw new ObjectCreationException("Failed to create instance for property "
+ throw new ObjectCreationException("Failed to create instance for property "
+ property.getName() + " with value " + aValue
+ " from value list of " + propertyValue, ex);
}
@@ -310,11 +316,11 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory { /**
* This method will create an instance of the value for the specified Property.
- *
+ *
* @param property The Property from which to retrieve the property value
* @param type The type of the property value being retrieved from the Property
* @param <B> Type type of the property value being looked up
- *
+ *
* @return the value for the Property
*/
public <B> B createPropertyValue(ComponentProperty property, Class<B> type)
diff --git a/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java b/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java index e585b3d46f..29e02da648 100644 --- a/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java +++ b/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java @@ -6,15 +6,15 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.implementation.java.invocation; @@ -37,6 +37,7 @@ import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Multiplicity; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.context.ComponentContextFactory; +import org.apache.tuscany.sca.context.PropertyValueFactory; import org.apache.tuscany.sca.context.RequestContextFactory; import org.apache.tuscany.sca.core.context.ComponentContextImpl; import org.apache.tuscany.sca.core.context.InstanceWrapper; @@ -68,7 +69,7 @@ import org.osoa.sca.annotations.ConversationID; /** * The runtime instantiation of Java component implementations - * + * * @version $Rev$ $Date$ */ public class JavaComponentContextProvider { @@ -81,7 +82,7 @@ public class JavaComponentContextProvider { public JavaComponentContextProvider(RuntimeComponent component, JavaInstanceFactoryProvider configuration, DataBindingExtensionPoint dataBindingExtensionPoint, - JavaPropertyValueObjectFactory propertyValueObjectFactory, + PropertyValueFactory propertyValueObjectFactory, ComponentContextFactory componentContextFactory, RequestContextFactory requestContextFactory) { super(); @@ -94,7 +95,7 @@ public class JavaComponentContextProvider { // } this.component = component; this.dataBindingRegistry = dataBindingExtensionPoint; - this.propertyValueFactory = propertyValueObjectFactory; + this.propertyValueFactory = (JavaPropertyValueObjectFactory) propertyValueObjectFactory; } InstanceWrapper<?> createInstanceWrapper() throws ObjectCreationException { @@ -132,7 +133,7 @@ public class JavaComponentContextProvider { ObjectFactory<?> propertyObjectFactory = createPropertyValueFactory(configuredProperty, configuredProperty.getValue(), element); instanceFactoryProvider.setObjectFactory(element, propertyObjectFactory); - + JavaConstructorImpl constructor = instanceFactoryProvider.getImplementation().getConstructor(); for(JavaElementImpl p: constructor.getParameters()){ if(element.getName().equals(p.getName())) { @@ -265,7 +266,7 @@ public class JavaComponentContextProvider { } // We need to set the PropertyValueFactory on the ComponentContextImpl - // so the ComponentContext can "de-marshal" the property type to a value + // so the ComponentContext can "de-marshal" the property type to a value // when the getProperty() method is called ComponentContextImpl ccImpl = (ComponentContextImpl)component.getComponentContext(); ccImpl.setPropertyValueFactory(propertyValueFactory); diff --git a/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java b/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java index e9eea607c9..10825ca4b6 100644 --- a/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java +++ b/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java @@ -6,15 +6,15 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.implementation.java.invocation; @@ -24,6 +24,7 @@ import java.util.List; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.context.ComponentContextFactory; +import org.apache.tuscany.sca.context.PropertyValueFactory; import org.apache.tuscany.sca.context.RequestContextFactory; import org.apache.tuscany.sca.core.context.InstanceWrapper; import org.apache.tuscany.sca.core.factory.ObjectFactory; @@ -33,7 +34,6 @@ import org.apache.tuscany.sca.core.scope.ScopedImplementationProvider; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; import org.apache.tuscany.sca.implementation.java.JavaImplementation; import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl; -import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; import org.apache.tuscany.sca.implementation.java.injection.RequestContextObjectFactory; import org.apache.tuscany.sca.implementation.java.injection.ResourceHost; import org.apache.tuscany.sca.implementation.java.injection.ResourceObjectFactory; @@ -55,12 +55,12 @@ public class JavaImplementationProvider implements ScopedImplementationProvider private JavaImplementation implementation; private JavaComponentContextProvider componentContextProvider; private RequestContextFactory requestContextFactory; - + public JavaImplementationProvider(RuntimeComponent component, JavaImplementation implementation, ProxyFactory proxyService, DataBindingExtensionPoint dataBindingRegistry, - JavaPropertyValueObjectFactory propertyValueObjectFactory, + PropertyValueFactory propertyValueObjectFactory, ComponentContextFactory componentContextFactory, RequestContextFactory requestContextFactory, List<PolicyHandlerTuple> policyHandlerClassNames) { @@ -68,16 +68,16 @@ public class JavaImplementationProvider implements ScopedImplementationProvider this.implementation = implementation; this.requestContextFactory = requestContextFactory; this.implementation.setPolicyHandlerClassNames(policyHandlerClassNames); - + try { JavaInstanceFactoryProvider configuration = new JavaInstanceFactoryProvider(implementation); configuration.setProxyFactory(proxyService); componentContextProvider = - new JavaComponentContextProvider(component, - configuration, + new JavaComponentContextProvider(component, + configuration, dataBindingRegistry, propertyValueObjectFactory, - componentContextFactory, + componentContextFactory, requestContextFactory); Scope scope = getScope(); @@ -110,9 +110,9 @@ public class JavaImplementationProvider implements ScopedImplementationProvider } catch (Exception e) { throw new IllegalStateException(e); } - + } - + private void handleResources(JavaImplementation componentType, ProxyFactory proxyService) { for (JavaResourceImpl resource : componentType.getResources().values()) { String name = resource.getName(); @@ -169,7 +169,7 @@ public class JavaImplementationProvider implements ScopedImplementationProvider } } } - + public boolean supportsOneWayInvocation() { return false; } diff --git a/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java b/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java index 9b78439012..a97d21e1e5 100644 --- a/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java +++ b/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java @@ -6,15 +6,15 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.implementation.java.invocation; @@ -22,11 +22,11 @@ package org.apache.tuscany.sca.implementation.java.invocation; import java.util.List; import org.apache.tuscany.sca.context.ComponentContextFactory; +import org.apache.tuscany.sca.context.PropertyValueFactory; import org.apache.tuscany.sca.context.RequestContextFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactory; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; import org.apache.tuscany.sca.implementation.java.JavaImplementation; -import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple; import org.apache.tuscany.sca.provider.ImplementationProvider; import org.apache.tuscany.sca.provider.ImplementationProviderFactory; @@ -36,7 +36,7 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent; * @version $Rev$ $Date$ */ public class JavaImplementationProviderFactory implements ImplementationProviderFactory<JavaImplementation> { - private JavaPropertyValueObjectFactory propertyValueObjectFactory; + private PropertyValueFactory propertyValueObjectFactory; private DataBindingExtensionPoint dataBindingRegistry; private ProxyFactory proxyService; private ComponentContextFactory componentContextFactory; @@ -45,7 +45,7 @@ public class JavaImplementationProviderFactory implements ImplementationProvider public JavaImplementationProviderFactory(ProxyFactory proxyService, DataBindingExtensionPoint dataBindingRegistry, - JavaPropertyValueObjectFactory propertyValueObjectFactory, + PropertyValueFactory propertyValueObjectFactory, ComponentContextFactory componentContextFactory, RequestContextFactory requestContextFactory, List<PolicyHandlerTuple> policyHandlerClassNames) { @@ -60,12 +60,12 @@ public class JavaImplementationProviderFactory implements ImplementationProvider public ImplementationProvider createImplementationProvider(RuntimeComponent component, JavaImplementation implementation) { - return new JavaImplementationProvider(component, - implementation, - proxyService, + return new JavaImplementationProvider(component, + implementation, + proxyService, dataBindingRegistry, - propertyValueObjectFactory, - componentContextFactory, + propertyValueObjectFactory, + componentContextFactory, requestContextFactory, policyHandlerClassNames); } diff --git a/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java b/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java index 31c91e2d6c..baf942ccd9 100644 --- a/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java +++ b/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java @@ -6,25 +6,25 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.implementation.java.module; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; import org.apache.tuscany.sca.context.ComponentContextFactory; import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint; +import org.apache.tuscany.sca.context.PropertyValueFactory; import org.apache.tuscany.sca.context.RequestContextFactory; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; @@ -35,9 +35,7 @@ import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; -import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; +import org.apache.tuscany.sca.databinding.Mediator; import org.apache.tuscany.sca.implementation.java.invocation.JavaCallbackRuntimeWireProcessor; import org.apache.tuscany.sca.implementation.java.invocation.JavaImplementationProviderFactory; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; @@ -62,7 +60,7 @@ public class JavaRuntimeModuleActivator implements ModuleActivator { ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); MessageFactory messageFactory = factories.getFactory(MessageFactory.class); - + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); InterfaceContractMapper interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); @@ -76,9 +74,8 @@ public class JavaRuntimeModuleActivator implements ModuleActivator { JavaInterfaceFactory javaFactory = factories.getFactory(JavaInterfaceFactory.class); DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); - TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); - MediatorImpl mediator = new MediatorImpl(dataBindings, transformers); - JavaPropertyValueObjectFactory factory = new JavaPropertyValueObjectFactory(mediator); + Mediator mediator = utilities.getUtility(Mediator.class); + PropertyValueFactory factory = utilities.getUtility(PropertyValueFactory.class); ContextFactoryExtensionPoint contextFactories = registry.getExtensionPoint(ContextFactoryExtensionPoint.class); ComponentContextFactory componentContextFactory = contextFactories.getFactory(ComponentContextFactory.class); @@ -86,9 +83,9 @@ public class JavaRuntimeModuleActivator implements ModuleActivator { List<PolicyHandlerTuple> policyHandlerClassNames = null; policyHandlerClassNames = PolicyHandlerDefinitionsLoader.loadPolicyHandlerClassnames(); - + ProxyFactory proxyFactory = new ExtensibleProxyFactory(proxyFactories); - + JavaImplementationProviderFactory javaImplementationProviderFactory = new JavaImplementationProviderFactory(proxyFactory, dataBindings, factory, componentContextFactory, requestContextFactory, policyHandlerClassNames); diff --git a/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.PropertyValueFactory b/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.PropertyValueFactory new file mode 100644 index 0000000000..f2feb6156a --- /dev/null +++ b/branches/sca-java-1.x/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.PropertyValueFactory @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory
\ No newline at end of file diff --git a/branches/sca-java-1.x/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java b/branches/sca-java-1.x/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java index 5664c77618..b49f94c1e0 100644 --- a/branches/sca-java-1.x/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java +++ b/branches/sca-java-1.x/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java @@ -6,15 +6,15 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.implementation.osgi.runtime; @@ -92,51 +92,51 @@ import org.osgi.service.packageadmin.PackageAdmin; * * @version $Rev$ $Date$ */ -public class OSGiImplementationProvider implements ScopedImplementationProvider, +public class OSGiImplementationProvider implements ScopedImplementationProvider, FrameworkListener, BundleListener { - + private static final String COMPONENT_SERVICE_NAME = "component.service.name"; - + // Maximum milliseconds to wait for a method to complete - private static final long METHOD_TIMEOUT_MILLIS = 60000; + private static final long METHOD_TIMEOUT_MILLIS = 60000; // Maximum milliseconds to wait for services to be registered into OSGi service registry - private static final long SERVICE_TIMEOUT_MILLIS = 300000; - + private static final long SERVICE_TIMEOUT_MILLIS = 300000; + private OSGiImplementationImpl implementation; private OSGiAnnotations osgiAnnotations; private BundleContext bundleContext; - + private Hashtable<RuntimeWire, Reference> referenceWires = new Hashtable<RuntimeWire,Reference>(); - private Hashtable<RuntimeWire, ComponentReference> componentReferenceWires + private Hashtable<RuntimeWire, ComponentReference> componentReferenceWires = new Hashtable<RuntimeWire,ComponentReference>(); - private HashSet<RuntimeWire> resolvedWires = new HashSet<RuntimeWire>(); + private HashSet<RuntimeWire> resolvedWires = new HashSet<RuntimeWire>(); private boolean wiresResolved; - - private AtomicInteger startBundleEntryCount = new AtomicInteger(); + + private AtomicInteger startBundleEntryCount = new AtomicInteger(); private AtomicInteger processAnnotationsEntryCount = new AtomicInteger(); - + private JavaPropertyValueObjectFactory propertyValueFactory; - + private Hashtable<String, Object> componentProperties = new Hashtable<String, Object>(); private RuntimeComponent runtimeComponent; - + private Bundle osgiBundle; private ArrayList<Bundle> dependentBundles = new ArrayList<Bundle>(); private OSGiServiceListener osgiServiceListener; private PackageAdmin packageAdmin; - + private OSGiRuntime osgiRuntime; - + private ScopeRegistry scopeRegistry; private DataBindingExtensionPoint dataBindingRegistry; - + private boolean packagesRefreshed; - + private MessageFactory messageFactory; private InterfaceContractMapper mapper; - + public OSGiImplementationProvider(RuntimeComponent definition, OSGiImplementation impl, @@ -147,8 +147,8 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider RequestContextFactory requestContextFactory, MessageFactory messageFactory, InterfaceContractMapper mapper) throws BundleException { - - + + this.implementation = (OSGiImplementationImpl)impl; this.runtimeComponent = definition; this.dataBindingRegistry = dataBindingRegistry; @@ -156,13 +156,13 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider this.scopeRegistry = scopeRegistry; this.messageFactory = messageFactory; this.mapper = mapper; - + bundleContext = getBundleContext(); osgiBundle = (Bundle)implementation.getOSGiBundle(); bundleContext.addBundleListener(this); - osgiServiceListener = new OSGiServiceListener(osgiBundle); - bundleContext.addServiceListener(osgiServiceListener); - + osgiServiceListener = new OSGiServiceListener(osgiBundle); + bundleContext.addServiceListener(osgiServiceListener); + // Install and start all dependent bundles String[] imports = implementation.getImports(); for (int i = 0; i < imports.length; i++) { @@ -170,9 +170,9 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider if (location.length() > 0) { Bundle bundle = bundleContext.installBundle(location); dependentBundles.add(bundle); - } + } } - + this.osgiAnnotations = new OSGiAnnotations( implementation.getModelFactories(), @@ -184,68 +184,68 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider osgiBundle, dependentBundles); - - // PackageAdmin is used to resolve bundles - org.osgi.framework.ServiceReference packageAdminReference = + + // PackageAdmin is used to resolve bundles + org.osgi.framework.ServiceReference packageAdminReference = bundleContext.getServiceReference("org.osgi.service.packageadmin.PackageAdmin"); if (packageAdminReference != null) { packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminReference); bundleContext.addFrameworkListener(this); } - - + + } - + protected RuntimeComponent getRuntimeComponent() { return runtimeComponent; } - + protected OSGiImplementationImpl getImplementation() { return implementation; } - - // Create a property table from the list of properties + + // Create a property table from the list of properties // The source properties are properties read from <property/> elements - // Create property values in the table of the appropriate class based + // Create property values in the table of the appropriate class based // on the property type specified. private void processProperties(List<?> props, Hashtable<String, Object> propsTable) { - + if (props != null) { for (Object p : props) { - + Property prop = (Property)p; Class javaType = SimpleTypeMapperImpl.getJavaType(prop.getXSDType()); ObjectFactory<?> objFactory = propertyValueFactory.createValueFactory(prop, prop.getValue(), javaType); - Object value = objFactory.getInstance(); + Object value = objFactory.getInstance(); propsTable.put(prop.getName(), value); } } } - + private BundleContext getBundleContext() throws BundleException { try { if (bundleContext == null) { osgiRuntime = OSGiRuntime.getRuntime(); - bundleContext = osgiRuntime .getBundleContext(); + bundleContext = osgiRuntime .getBundleContext(); } } catch (BundleException e) { throw e; } catch (Exception e) { throw new BundleException("Could not start OSGi runtime", e); } - - + + return bundleContext; } - - + + private String getOSGiFilter(Hashtable<String, Object> props) { - + String filter = ""; - + if (props != null && props.size() > 0) { int propCount = 0; for (String propName : props.keySet()) { @@ -254,35 +254,35 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider filter = filter + "(" + propName + "=" + props.get(propName) + ")"; propCount++; } - + if (propCount > 1) filter = "(&" + filter + ")"; } else filter = null; return filter; } - + /* * Return a matching service registered by the specified bundle. * If <implementation.osgi /> has the attribute filter defined, return a service * reference that matches the filter. Otherwise, return a service which has a component * name equal to this component's name. If not found, return a service which no * component name set. - * + * * Even though services registered by this bundle can be filtered using the - * service listener, we use this method to filter all service references so that + * service listener, we use this method to filter all service references so that * the service matching functionality of OSGi can be directly used. */ - private org.osgi.framework.ServiceReference getOSGiServiceReference( + private org.osgi.framework.ServiceReference getOSGiServiceReference( String scaServiceName, - String osgiServiceName, String filter) + String osgiServiceName, String filter) throws InvalidSyntaxException { - + String compServiceName = runtimeComponent.getName() + "/" + scaServiceName; if (filter != null && filter.length() > 0) { - org.osgi.framework.ServiceReference[] references = + org.osgi.framework.ServiceReference[] references = bundleContext.getServiceReferences(osgiServiceName, filter); - + org.osgi.framework.ServiceReference reference = null; if (references != null) { @@ -298,32 +298,32 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider } } } - + return reference; - + } - - filter = scaServiceName == null? null : + + filter = scaServiceName == null? null : "(" + COMPONENT_SERVICE_NAME + "="+ compServiceName + ")"; - - org.osgi.framework.ServiceReference[] references = + + org.osgi.framework.ServiceReference[] references = bundleContext.getServiceReferences(osgiServiceName, filter); - - if (references != null) { + + if (references != null) { for (org.osgi.framework.ServiceReference ref : references) { if (ref.getBundle() == osgiBundle) { return ref; } } } - + references = bundleContext.getServiceReferences(osgiServiceName, null); - + org.osgi.framework.ServiceReference reference = null; - + if (references != null) { for (org.osgi.framework.ServiceReference ref : references) { - + if (ref.getBundle() != osgiBundle) continue; Object compName = ref.getProperty(COMPONENT_SERVICE_NAME); @@ -335,21 +335,21 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider } } } - + return reference; } - + /** * This method is used to avoid full synchronization of methods which should - * be executed only once. - * + * be executed only once. + * * entryCount=0: The count is incremented, and this thread executes the method. Returns true. - * - * entryCount=1: Another thread is already executing this method. - * Wait for the thread to complete if doWait is true. Returns false. - * + * + * entryCount=1: Another thread is already executing this method. + * Wait for the thread to complete if doWait is true. Returns false. + * * entryCount=2: The method has already been executed. Returns false. - * + * * @param doWait If true, and another method is executing this method * wait for method execution to complete * @param entryCount Atomic integer used to ensure that the method is @@ -357,7 +357,7 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider * @return true if this thread has exclusive access to execute this method */ private boolean enterMethod(boolean doWait, AtomicInteger entryCount) { - + if (entryCount.compareAndSet(0, 1)) { return true; } @@ -375,12 +375,12 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider return false; } } - + /** - * Called on method exit of methods which were entered after + * Called on method exit of methods which were entered after * enterMethod returned true. Increments entryCount, and wakes * up threads waiting for the method to complete. - * + * * @param entryCount Atomic integer used for synchronization */ private void exitMethod(AtomicInteger entryCount) { @@ -389,20 +389,20 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider entryCount.notifyAll(); } } - + protected Bundle startBundle(boolean doWait) throws ObjectCreationException { try { - - if (enterMethod(doWait, startBundleEntryCount)) { - + + if (enterMethod(doWait, startBundleEntryCount)) { + configurePropertiesUsingConfigAdmin(); - + resolveBundle(); - + processAnnotations(true); - - + + for (Bundle bundle : dependentBundles) { try { if (bundle.getState() != Bundle.ACTIVE && bundle.getState() != Bundle.STARTING) { @@ -413,14 +413,14 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider throw e; } } - + } - + if (osgiBundle.getState() != Bundle.ACTIVE && osgiBundle.getState() != Bundle.STARTING) { - + int retry = 0; - + while (retry++ < 10) { try { AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { @@ -433,15 +433,15 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider // } catch ( BundleException e) { } catch ( PrivilegedActionException e) { // It is possible that the thread "Refresh Packages" is in the process of - // changing the state of this bundle. + // changing the state of this bundle. Thread.yield(); - + if (retry == 10) throw e; } } - } - + } + } catch (Exception e) { throw new ObjectCreationException(e); } finally { @@ -449,32 +449,32 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider } return osgiBundle; } - - + + // This method is called by OSGiInstanceWrapper.getInstance to obtain the OSGi service reference // corresponding to the specified service. The properties used to filter the service should // be chosen based on whether this is a normal service or a callback. - protected org.osgi.framework.ServiceReference getOSGiServiceReference(ComponentService service) + protected org.osgi.framework.ServiceReference getOSGiServiceReference(ComponentService service) throws ObjectCreationException { - + Hashtable<String, Object> props = new Hashtable<String, Object>(); if (!service.isCallback()) processProperties(implementation.getServiceProperties(service.getName()), props); else processProperties(implementation.getServiceCallbackProperties(service.getName()), props); - + String filter = getOSGiFilter(props); Interface serviceInterface = service.getInterfaceContract().getInterface(); String scaServiceName = service.getName(); - + return getOSGiServiceReference(serviceInterface, filter, scaServiceName); - + } - + protected org.osgi.framework.ServiceReference getOSGiServiceReference( - EndpointReference from, Interface callbackInterface) + EndpointReference from, Interface callbackInterface) throws ObjectCreationException { - + RuntimeWire refWire = null; String filter = null; for (RuntimeWire wire : referenceWires.keySet()) { @@ -489,58 +489,58 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider processProperties(implementation.getReferenceCallbackProperties(scaRef.getName()), props); filter = getOSGiFilter(props); } - + return getOSGiServiceReference(callbackInterface, filter, null); } - + private org.osgi.framework.ServiceReference getOSGiServiceReference(Interface serviceInterface, String filter, String scaServiceName) throws ObjectCreationException { - + try { - + String serviceInterfaceName = null; org.osgi.framework.ServiceReference osgiServiceReference = null; - + if (serviceInterface instanceof JavaInterface) { serviceInterfaceName = ((JavaInterface)serviceInterface).getJavaClass().getName(); - - if ((osgiServiceReference = getOSGiServiceReference( + + if ((osgiServiceReference = getOSGiServiceReference( scaServiceName, serviceInterfaceName, filter)) == null) { - + // The service listener for our bundle will notify us when the service is registered. - synchronized (implementation) { - + synchronized (implementation) { + // When declarative services are used, the component is started asynchronously // So this thread has to wait for the service to be registered by the component // activate method // For regular bundle activators, bundle.start activates the bundle synchronously // and hence the service would probably have been started by the bundle activator long startTime = System.currentTimeMillis(); - while ((osgiServiceReference = getOSGiServiceReference( + while ((osgiServiceReference = getOSGiServiceReference( scaServiceName, serviceInterfaceName, filter)) == null) { - + // Wait for the bundle to register the service implementation.wait(100); if (System.currentTimeMillis() - startTime > SERVICE_TIMEOUT_MILLIS) break; } - } - + } + } } - + return osgiServiceReference; - + } catch (Exception e) { throw new ObjectCreationException(e); } } - - + + // Felix does not support bundle fragments. This is a temporary workaround. protected Bundle installDummyBundleWithoutFragments(Class<?> interfaceClass) throws Exception { @@ -558,7 +558,7 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider + bundleName + EOL + "Bundle-SymbolicName: " + bundleName + EOL + "Bundle-Version: " + "1.0.0" + EOL + "Bundle-Localization: plugin" + EOL; - + ArrayList<String> dummyClasses = new ArrayList<String>(); StringBuilder manifestBuf = new StringBuilder(); @@ -571,10 +571,10 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider for (Class<?> clazz : interfaceClass.getClasses()) { dummyClasses.add(clazz.getName()); } - if (existingBundle != null && + if (existingBundle != null && (existingClasses = (String)existingBundle.getHeaders().get("SCA-Dummy-Classes")) != null) { exportedInterfaces = exportedInterfaces + " " + existingClasses; - + StringTokenizer tokenizer = new StringTokenizer(existingClasses); while (tokenizer.hasMoreTokens()) { String className = tokenizer.nextToken(); @@ -595,23 +595,23 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider for (int i = 0; i < dummyClasses.size(); i++) { String className = dummyClasses.get(i); - + Class clazz = interfaceClass.getClassLoader().loadClass(className); className = clazz.getName().replaceAll("\\.", "/") + ".class"; ZipEntry ze = new ZipEntry(className); jarOut.putNextEntry(ze); InputStream stream = clazz.getResourceAsStream(clazz.getSimpleName() + ".class"); - + byte[] bytes = new byte[stream.available()]; stream.read(bytes); jarOut.write(bytes); stream.close(); } - - + + jarOut.close(); out.close(); - + if (existingBundle != null) { existingBundle.stop(); existingBundle.uninstall(); @@ -623,129 +623,129 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider + ".jar", in); bundle.start(); - + if (existingBundle != null && packageAdmin != null) { refreshPackages(); - + } return bundle; } - + private Bundle getDummyHostBundle(String packageName) { - + if (packageAdmin == null) return null; - + ExportedPackage exp = packageAdmin.getExportedPackage(packageName); if (exp == null) return null; else return exp.getExportingBundle(); } - + private static String getPackageName(Class<?> cls) { String name = cls.getName(); int index = name.lastIndexOf('.'); return index == -1 ? "" : name.substring(0, index); } - + private Bundle installDummyBundle(Class<?> interfaceClass) throws Exception { - + if (!osgiRuntime.supportsBundleFragments()) { return installDummyBundleWithoutFragments(interfaceClass); } - + ByteArrayOutputStream out = new ByteArrayOutputStream(); - + String EOL = System.getProperty("line.separator"); ArrayList<Class<?>> dummyClasses = new ArrayList<Class<?>>(); - + String interfaceName = interfaceClass.getName(); String packageName = getPackageName(interfaceClass); String bundleName = "dummy.sca." + interfaceName; - - + + String manifestStr = "Manifest-Version: 1.0" + EOL + "Bundle-ManifestVersion: 2" + EOL + "Bundle-Name: " + bundleName + EOL + "Bundle-SymbolicName: " + bundleName + EOL + "Bundle-Version: " + "1.0.0" + EOL + "Bundle-Localization: plugin" + EOL; - - + + StringBuilder manifestBuf = new StringBuilder(); manifestBuf.append(manifestStr); manifestBuf.append("Export-Package: " + packageName + EOL); Bundle dummyHost = getDummyHostBundle(packageName); if (dummyHost != null) manifestBuf.append("Fragment-Host: " + dummyHost.getSymbolicName() + EOL); - + ByteArrayInputStream manifestStream = new ByteArrayInputStream(manifestBuf.toString().getBytes()); Manifest manifest = new Manifest(); manifest.read(manifestStream); - + dummyClasses.add(interfaceClass); for (Class<?> clazz : interfaceClass.getClasses()) { dummyClasses.add(clazz); } - + JarOutputStream jarOut = new JarOutputStream(out, manifest); for (int i = 0; i < dummyClasses.size(); i++) { - + Class<?> clazz = dummyClasses.get(i); String className = clazz.getName(); className = clazz.getName().replaceAll("\\.", "/") + ".class"; ZipEntry ze = new ZipEntry(className); jarOut.putNextEntry(ze); InputStream stream = clazz.getResourceAsStream(clazz.getSimpleName() + ".class"); - + byte[] bytes = new byte[stream.available()]; stream.read(bytes); jarOut.write(bytes); stream.close(); } - + jarOut.close(); out.close(); - - + + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); - - + + Bundle bundle = bundleContext.installBundle( "file://" + bundleName + ".jar", in); - + if (dummyHost == null) bundle.start(); - + return bundle; - + } - - - + + + public InstanceWrapper<?> createInstanceWrapper() throws ObjectCreationException { - + return new OSGiInstanceWrapper<Object>(this, osgiAnnotations, bundleContext); } - - - + + + private void resolveWireCreateDummyBundles(final Class interfaceClass) throws Exception { - - + + try { - + osgiBundle.loadClass(interfaceClass.getName()); - + } catch (ClassNotFoundException e) { - + // The interface used by the proxy is not in the source bundle // A dummy bundle needs to be installed to create the proxy // Allow privileged access to file system. Requires FileSystem permission in security @@ -755,89 +755,89 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider return installDummyBundle(interfaceClass); } }); - + if (packageAdmin != null) { - + packageAdmin.resolveBundles(new Bundle[]{dummyBundle, osgiBundle}); - - } + + } } } - + /** * For OSGi->Java wires, create a proxy corresponding to the Java interfaces - * and register the proxy with the OSGi registry, so that the source OSGi bundle can + * and register the proxy with the OSGi registry, so that the source OSGi bundle can * locate the target Java instance from the registry like a regular OSGi service. - * + * * For OSGi->OSGi wires, start the target OSGi bundle, so that references of the * target are resolved before the source OSGi bundle is started. If the reference * has properties specified, create a Proxy and register a service with highest * possible ranking. The Proxy should wire to the correct OSGi instance specified * in the SCA composite. - * + * * The first phase determines whether a proxy should be installed. It also registers * a dummy bundle if necessary to resolve the bundle. When phase1 is completed on all * wires of the component, the bundle should be resolved. Phase2 registers the proxy service. */ private boolean resolveWireResolveReferences(Bundle bundle, Class interfaceClass, RuntimeWire wire, boolean isOSGiToOSGiWire) throws Exception { - + // FIXME: At the moment injection of values into instances require an instance to be obtained // through the instance wrapper, and hence requires a proxy. When we do this processing here, // we don't yet know whether the target requires any property or callback injection. So it is - // safer to create a proxy all the time. - boolean createProxy = true; - + // safer to create a proxy all the time. + boolean createProxy = true; + ComponentReference scaRef = componentReferenceWires.get(wire); Hashtable<String, Object> targetProperties = new Hashtable<String, Object>(); processProperties(implementation.getReferenceProperties(scaRef.getName()), targetProperties); - + if (isOSGiToOSGiWire) { - + OSGiImplementationProvider implProvider = (OSGiImplementationProvider)wire.getTarget().getComponent().getImplementationProvider(); - + // This is an OSGi->OSGi wire isOSGiToOSGiWire = true; - - // If the target component is stateless, use a proxy to create a new service each time + + // If the target component is stateless, use a proxy to create a new service each time if (!implProvider.getScope().equals(Scope.COMPOSITE)) createProxy = true; - + Interface interfaze = wire.getTarget().getInterfaceContract().getInterface(); - + // If the target interface is remotable, create a proxy to support pass-by-value semantics // AllowsPassByReference is not detected until the target instance is obtained. if (interfaze.isRemotable()) createProxy = true; - + // If any of the operations in the target interface is non-blocking, create a proxy List<Operation> ops = interfaze.getOperations(); for (Operation op : ops) { if (op.isNonBlocking()) createProxy = true; } - + // If properties are specified for the reference, create a proxy since rewiring may be required if (targetProperties.size() > 0) { createProxy = true; } - + // If properties are specified for the component, create a proxy for configuring // the component services. if (componentProperties.size() > 0) { createProxy = true; } - + // Since this is an OSGi->OSGi wire, start the target bundle before starting the - // source bundle if there is no proxy. For direct wiring without a proxy, this ordering - // is irrelevant in terms of class resolution, but the target needs to be started at some - // point. But there is no opportunity later on to start the target OSGi bundle without a proxy. + // source bundle if there is no proxy. For direct wiring without a proxy, this ordering + // is irrelevant in terms of class resolution, but the target needs to be started at some + // point. But there is no opportunity later on to start the target OSGi bundle without a proxy. // When a Proxy is used, the target bundle needs to be resolved for the source bundle // to be resolved so that the interface is visible to the source. In this case the bundle - // will be started when an instance is needed. - if (!createProxy) { + // will be started when an instance is needed. + if (!createProxy) { implProvider.startBundle(false); } else { @@ -847,26 +847,26 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider else { createProxy = true; } - + return createProxy; } - - - // Register proxy service + + + // Register proxy service private void resolveWireRegisterProxyService(final Bundle bundle, final Class interfaceClass, RuntimeWire wire) throws Exception { - + ComponentReference scaRef = componentReferenceWires.get(wire); Hashtable<String, Object> targetProperties = new Hashtable<String, Object>(); processProperties(implementation.getReferenceProperties(scaRef.getName()), targetProperties); targetProperties.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE); - + if (targetProperties.get(COMPONENT_SERVICE_NAME) == null && wire.getTarget().getComponent() != null) { - String compServiceName = wire.getTarget().getComponent().getName() + "/" + + String compServiceName = wire.getTarget().getComponent().getName() + "/" + wire.getTarget().getContract().getName(); targetProperties.put(COMPONENT_SERVICE_NAME, compServiceName); } - - + + JDKProxyFactory proxyService = new JDKProxyFactory(messageFactory, mapper); // Allow privileged access to load classes. Requires getClassLoader permission in security @@ -885,18 +885,18 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider return null; } }); - - + + } - - + + private void refreshPackages() { - + if (packageAdmin != null) { synchronized (this) { packagesRefreshed = false; packageAdmin.refreshPackages(null); - + if (!packagesRefreshed) { try { this.wait(2000); @@ -905,24 +905,24 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider } } packagesRefreshed = false; - } + } } } - - + + private void resolveBundle() throws ObjectCreationException { - - + + try { - + if (!wiresResolved) { wiresResolved = true; - + if (!setReferencesAndProperties()) { wiresResolved = false; return; } - + int refPlusServices = referenceWires.size() + runtimeComponent.getServices().size(); boolean[] createProxyService = new boolean[refPlusServices]; Class<?>[] interfaceClasses = new Class<?>[refPlusServices] ; @@ -930,47 +930,47 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider boolean[] wireResolved = new boolean[refPlusServices]; int index = 0; for (RuntimeWire wire : referenceWires.keySet()) { - + Reference reference = referenceWires.get(wire); - + isOSGiToOSGiWire[index] = wire.getTarget().getComponent() != null && - wire.getTarget().getComponent().getImplementationProvider() + wire.getTarget().getComponent().getImplementationProvider() instanceof OSGiImplementationProvider; - + Interface refInterface = reference.getInterfaceContract().getInterface(); if (refInterface instanceof JavaInterface) { interfaceClasses[index] = ((JavaInterface)refInterface).getJavaClass(); - + if (!isOSGiToOSGiWire[index]) resolveWireCreateDummyBundles(interfaceClasses[index]); } - + if (!resolvedWires.contains(wire)) { - resolvedWires.add(wire); + resolvedWires.add(wire); } else wireResolved[index] = true; - + index++; } for (ComponentService service : runtimeComponent.getServices()) { Interface callbackInterface = service.getInterfaceContract().getCallbackInterface(); if (callbackInterface instanceof JavaInterface) { interfaceClasses[index] = ((JavaInterface)callbackInterface).getJavaClass(); - + resolveWireCreateDummyBundles(interfaceClasses[index]); } - + index++; } - + index = 0; for (RuntimeWire wire : referenceWires.keySet()) { - + if (!wireResolved[index]) { - createProxyService[index] = resolveWireResolveReferences(osgiBundle, - interfaceClasses[index], + createProxyService[index] = resolveWireResolveReferences(osgiBundle, + interfaceClasses[index], wire, isOSGiToOSGiWire[index]); } @@ -978,11 +978,11 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider } refreshPackages(); - - + + index = 0; for (RuntimeWire wire : referenceWires.keySet()) { - + if (createProxyService[index] && !wireResolved[index]) resolveWireRegisterProxyService(osgiBundle, interfaceClasses[index], wire); index++; @@ -991,48 +991,48 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider else if (osgiBundle.getState() == Bundle.INSTALLED && packageAdmin != null) { packageAdmin.resolveBundles(new Bundle[] {osgiBundle}); } - + } catch (Exception e) { e.printStackTrace(); throw new ObjectCreationException(e); - } + } } - - + + @SuppressWarnings("unchecked") private void configurePropertiesUsingConfigAdmin() { - + try { if (componentProperties.size() == 0) return; - - org.osgi.framework.ServiceReference configAdminReference = + + org.osgi.framework.ServiceReference configAdminReference = bundleContext.getServiceReference("org.osgi.service.cm.ConfigurationAdmin"); if (configAdminReference != null) { - + Object cm = bundleContext.getService(configAdminReference); Class cmClass = cm.getClass().getClassLoader().loadClass("org.osgi.service.cm.ConfigurationAdmin"); Method getConfigMethod = cmClass.getMethod("getConfiguration", String.class, String.class); - + Class configClass = cm.getClass().getClassLoader().loadClass("org.osgi.service.cm.Configuration"); - + Method getMethod = configClass.getMethod("getProperties"); Method updateMethod = configClass.getMethod("update", Dictionary.class); - + List<Service> services = implementation.getServices(); HashSet<String> pidsProcessed = new HashSet<String>(); - + for (Service service : services) { - + List<ComponentProperty> serviceProps = implementation.getServiceProperties(service.getName()); String pid = null; - + if (serviceProps != null) { for (ComponentProperty prop : serviceProps) { if (prop.getName().equals("service.pid")) { - ObjectFactory objFactory = propertyValueFactory.createValueFactory(prop, + ObjectFactory objFactory = propertyValueFactory.createValueFactory(prop, prop.getValue(), String.class); pid = (String)objFactory.getInstance(); } @@ -1040,10 +1040,10 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider } if (pid == null || pidsProcessed.contains(pid)) continue; - - - + + + Object config = getConfigMethod.invoke(cm, pid, null); Dictionary props = (Dictionary) getMethod.invoke(config); if (props == null) @@ -1052,26 +1052,26 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider props.put(propertyName, componentProperties.get(propertyName)); } - + updateMethod.invoke(config, props); - - - } - + + + } + } - + } catch (Exception e) { e.printStackTrace(); } } - - - + + + public boolean isOptimizable() { return false; } - + public Scope getScope() { return osgiAnnotations.getScope(); } @@ -1087,15 +1087,15 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider public long getMaxIdleTime() { return osgiAnnotations.getMaxIdleTime(); } - + protected ScopeContainer<?> getScopeContainer() { startBundle(true); return ((ScopedRuntimeComponent)runtimeComponent).getScopeContainer(); } - + public Invoker createTargetInvoker(RuntimeComponentService service, Operation operation) { - - + + Interface serviceInterface = operation.getInterface(); boolean isRemotable = serviceInterface.isRemotable(); @@ -1106,39 +1106,39 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider } else { return invoker; } - + } - - + + public Invoker createInvoker(RuntimeComponentService service, Operation operation) { return createTargetInvoker(service, operation); } - + public boolean supportsOneWayInvocation() { return false; } private boolean setReferencesAndProperties() { - + for (Reference ref: implementation.getReferences()) { List<RuntimeWire> wireList = null; ComponentReference compRef = null; for (ComponentReference cRef : runtimeComponent.getReferences()) { if (cRef.getName().equals(ref.getName())) { - + wireList = ((RuntimeComponentReference)cRef).getRuntimeWires(); - + compRef = cRef; break; } } - + if (ref.getMultiplicity() == Multiplicity.ONE_N || ref.getMultiplicity() == Multiplicity.ZERO_N) { for (RuntimeWire wire : wireList) { referenceWires.put(wire, ref); componentReferenceWires.put(wire, compRef); } - + } else { if (wireList == null && ref.getMultiplicity() == Multiplicity.ONE_ONE) { throw new IllegalStateException("Required reference is missing: " + ref.getName()); @@ -1148,29 +1148,29 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider referenceWires.put(wire, ref); componentReferenceWires.put(wire, compRef); } - + } - + } - + processProperties(runtimeComponent.getProperties(), componentProperties); - + return true; - + } - + public void start() { setReferencesAndProperties(); } - + public void processAnnotations(boolean doWait) throws IntrospectionException { - + if (!enterMethod(doWait, processAnnotationsEntryCount)) return; - + try { osgiAnnotations.processAnnotations(); - + Scope scope = osgiAnnotations.getScope(); if (scope.equals(Scope.SYSTEM) || scope.equals(Scope.COMPOSITE)) { // Nothing @@ -1187,65 +1187,65 @@ public class OSGiImplementationProvider implements ScopedImplementationProvider if (oldScopeContainer != null && oldScopeContainer.getLifecycleState() == ScopeContainer.RUNNING) { scopeContainer.start(); } - + component.setScopeContainer(scopeContainer); } } } finally { exitMethod(processAnnotationsEntryCount); - } + } } - + public void stop() { if (osgiServiceListener != null) bundleContext.removeServiceListener(osgiServiceListener); } - - + + public void frameworkEvent(FrameworkEvent event) { if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) { synchronized (this) { packagesRefreshed = true; this.notifyAll(); - } + } } - + } - + public void bundleChanged(BundleEvent event) { if (event.getType() == BundleEvent.RESOLVED && event.getBundle() == osgiBundle) { try { processAnnotations(false); } catch (Throwable e) { e.printStackTrace(); - } + } } } private class OSGiServiceListener implements ServiceListener { - + private Bundle bundle; - + OSGiServiceListener(Bundle bundle) { this.bundle = bundle; } - + public void serviceChanged(org.osgi.framework.ServiceEvent event) { - + org.osgi.framework.ServiceReference reference = event.getServiceReference(); - + if (event.getType() == ServiceEvent.REGISTERED && reference.getBundle() == bundle) { - + synchronized (implementation) { - + implementation.notifyAll(); } } - + if (event.getType() == ServiceEvent.UNREGISTERING && reference.getBundle() == bundle) { // TODO: Process deregistering of OSGi services. } diff --git a/branches/sca-java-1.x/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java b/branches/sca-java-1.x/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java index 814d37f203..1a13ef99f7 100644 --- a/branches/sca-java-1.x/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java +++ b/branches/sca-java-1.x/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java @@ -6,15 +6,15 @@ * to you 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. + * under the License. */ package org.apache.tuscany.sca.implementation.osgi.runtime; @@ -29,8 +29,7 @@ import org.apache.tuscany.sca.core.invocation.ProxyFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; import org.apache.tuscany.sca.core.scope.ScopeRegistry; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; +import org.apache.tuscany.sca.databinding.Mediator; import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; @@ -47,48 +46,47 @@ import org.osgi.framework.BundleException; * @version $Rev$ $Date$ */ public class OSGiImplementationProviderFactory implements ImplementationProviderFactory<OSGiImplementation> { - + private DataBindingExtensionPoint dataBindings; private JavaPropertyValueObjectFactory propertyFactory; private ProxyFactory proxyFactory; private ScopeRegistry scopeRegistry; private MessageFactory messageFactory; private InterfaceContractMapper mapper; - + private RequestContextFactory requestContextFactory; - + public OSGiImplementationProviderFactory(ExtensionPointRegistry extensionPoints ) { - + dataBindings = extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class); ProxyFactoryExtensionPoint proxyFactories = extensionPoints.getExtensionPoint(ProxyFactoryExtensionPoint.class); proxyFactory = new ExtensibleProxyFactory(proxyFactories); ContextFactoryExtensionPoint contextFactories = extensionPoints.getExtensionPoint(ContextFactoryExtensionPoint.class); requestContextFactory = contextFactories.getFactory(RequestContextFactory.class); - + // FIXME: Scope registry is not an extension point, and this usage is specific // to implementation.osgi since it needs to change scope after the component is // created. Do we need to find a better way? scopeRegistry = extensionPoints.getExtensionPoint(ScopeRegistry.class); - - TransformerExtensionPoint transformers = extensionPoints.getExtensionPoint(TransformerExtensionPoint.class); - MediatorImpl mediator = new MediatorImpl(dataBindings, transformers); + + Mediator mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); propertyFactory = new JavaPropertyValueObjectFactory(mediator); ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); messageFactory = modelFactories.getFactory(MessageFactory.class); - + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); mapper = utilities.getUtility(InterfaceContractMapper.class); } public ImplementationProvider createImplementationProvider(RuntimeComponent component, OSGiImplementation implementation) { - + try { - - return new OSGiImplementationProvider(component, - implementation, + + return new OSGiImplementationProvider(component, + implementation, dataBindings, propertyFactory, proxyFactory, @@ -97,11 +95,11 @@ public class OSGiImplementationProviderFactory implements ImplementationProvider messageFactory, mapper ); - + } catch (BundleException e) { throw new RuntimeException(e); } - + } public Class<OSGiImplementation> getModelType() { diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationProviderFactory.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationProviderFactory.java index 1789b5a4e0..9f46683bcb 100644 --- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationProviderFactory.java +++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationProviderFactory.java @@ -21,12 +21,11 @@ package org.apache.tuscany.sca.implementation.spring; import java.util.List; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; +import org.apache.tuscany.sca.databinding.Mediator; import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; import org.apache.tuscany.sca.policy.util.PolicyHandlerDefinitionsLoader; import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple; @@ -36,7 +35,7 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent; /** * ImplementationProviderFactory for Spring implementation type - * @version $Rev: 511195 $ $Date: 2007-02-24 02:29:46 +0000 (Sat, 24 Feb 2007) $ + * @version $Rev: 511195 $ $Date: 2007-02-24 02:29:46 +0000 (Sat, 24 Feb 2007) $ * */ public class SpringImplementationProviderFactory implements ImplementationProviderFactory<SpringImplementation> { @@ -51,16 +50,13 @@ public class SpringImplementationProviderFactory implements ImplementationProvid */ public SpringImplementationProviderFactory(ExtensionPointRegistry extensionPoints) { super(); - - ProxyFactoryExtensionPoint proxyFactories = extensionPoints.getExtensionPoint(ProxyFactoryExtensionPoint.class); - proxyFactory = new ExtensibleProxyFactory(proxyFactories); - // TODO: could the runtime have a default PropertyValueObjectFactory? - DataBindingExtensionPoint dataBindings = extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class); - TransformerExtensionPoint transformers = extensionPoints.getExtensionPoint(TransformerExtensionPoint.class); - MediatorImpl mediator = new MediatorImpl(dataBindings, transformers); + ProxyFactoryExtensionPoint proxyFactories = extensionPoints.getExtensionPoint(ProxyFactoryExtensionPoint.class); + proxyFactory = new ExtensibleProxyFactory(proxyFactories); + + Mediator mediator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); propertyFactory = new JavaPropertyValueObjectFactory(mediator); - + policyHandlerClassNames = PolicyHandlerDefinitionsLoader.loadPolicyHandlerClassnames(); } @@ -73,10 +69,10 @@ public class SpringImplementationProviderFactory implements ImplementationProvid */ public ImplementationProvider createImplementationProvider(RuntimeComponent component, SpringImplementation implementation) { - return new SpringImplementationProvider(component, - implementation, - proxyFactory, - propertyFactory, + return new SpringImplementationProvider(component, + implementation, + proxyFactory, + propertyFactory, policyHandlerClassNames); } diff --git a/branches/sca-java-1.x/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryImplementationProviderFactory.java b/branches/sca-java-1.x/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryImplementationProviderFactory.java index 57536e502b..05c4c51086 100644 --- a/branches/sca-java-1.x/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryImplementationProviderFactory.java +++ b/branches/sca-java-1.x/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryImplementationProviderFactory.java @@ -19,9 +19,8 @@ package org.apache.tuscany.sca.implementation.xquery; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; import org.apache.tuscany.sca.provider.ImplementationProvider; import org.apache.tuscany.sca.provider.ImplementationProviderFactory; @@ -36,9 +35,7 @@ public class XQueryImplementationProviderFactory implements ImplementationProvid private JavaPropertyValueObjectFactory javaFactory; public XQueryImplementationProviderFactory(ExtensionPointRegistry registry) { - DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); - TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); - MediatorImpl mediator = new MediatorImpl(dataBindings, transformers); + Mediator mediator = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class); this.javaFactory = new JavaPropertyValueObjectFactory(mediator); } |