summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/databinding/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-04-30 04:39:55 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-04-30 04:39:55 +0000
commit563383415f9efeb2ff9420f0097989e5b79a6257 (patch)
tree541c21b1ad15cfae8f057a70197b0e564dde3904 /branches/sca-java-1.x/modules/databinding/src
parentb61cf23bd501dfde37fbef4056a7b1148ae92268 (diff)
Fix for TUSCANY-3000
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@770058 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/databinding/src')
-rw-r--r--branches/sca-java-1.x/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java28
-rw-r--r--branches/sca-java-1.x/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java32
-rw-r--r--branches/sca-java-1.x/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.Mediator17
3 files changed, 60 insertions, 17 deletions
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