diff options
Diffstat (limited to 'branches/sca-android-r643746/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java')
-rw-r--r-- | branches/sca-android-r643746/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/branches/sca-android-r643746/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java b/branches/sca-android-r643746/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java deleted file mode 100644 index 471cfde136..0000000000 --- a/branches/sca-android-r643746/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java +++ /dev/null @@ -1,114 +0,0 @@ -/*
- * 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.
- */
-package org.apache.tuscany.sca.contribution.resolver;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
-import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
-
-
-/**
- * The default implementation of a model resolver extension point.
- *
- * @version $Rev: 632642 $ $Date: 2008-03-01 10:16:44 -0800 (Sat, 01 Mar 2008) $
- */
-public class DefaultModelResolverExtensionPoint implements ModelResolverExtensionPoint {
-
- private final Map<Class<?>, Class<? extends ModelResolver>> resolvers = new HashMap<Class<?>, Class<? extends ModelResolver>>();
- private Map<String, ServiceDeclaration> loadedResolvers;
-
- /**
- * Constructs a new DefaultModelResolverExtensionPoint.
- */
- public DefaultModelResolverExtensionPoint() {
- }
-
- public void addResolver(Class<?> modelType, Class<? extends ModelResolver> resolver) {
- resolvers.put(modelType, resolver);
- }
-
- public void removeResolver(Class<?> modelType) {
- resolvers.remove(modelType);
- }
-
- @SuppressWarnings("unchecked")
- public Class<? extends ModelResolver> getResolver(Class<?> modelType) {
- loadModelResolvers();
-
- Class<?>[] classes = modelType.getInterfaces();
- for (Class<?> c : classes) {
- Class<? extends ModelResolver> resolver = resolvers.get(c);
- if (resolver == null) {
- ServiceDeclaration resolverClass = loadedResolvers.get(c.getName());
- if (resolverClass != null) {
- try {
- return (Class<? extends ModelResolver>)resolverClass.loadClass();
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException(e);
- }
- }
- } else {
- return resolver;
- }
- }
-
- Class<? extends ModelResolver > resolver = resolvers.get(modelType);
- if (resolver == null) {
- ServiceDeclaration resolverClass = loadedResolvers.get(modelType.getName());
- if (resolverClass != null) {
- try {
- return (Class<? extends ModelResolver>)resolverClass.loadClass();
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException(e);
- }
- }
- }
- return resolver;
- }
-
- /**
- * Dynamically load model resolvers declared under META-INF/services
- */
- private void loadModelResolvers() {
- if (loadedResolvers != null)
- return;
- loadedResolvers = new HashMap<String, ServiceDeclaration>();
-
- // Get the model resolver service declarations
- Set<ServiceDeclaration> modelResolverDeclarations;
- try {
- modelResolverDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ModelResolver.class);
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
-
- // Load model resolvers
- for (ServiceDeclaration dataBindingDeclaration: modelResolverDeclarations) {
- Map<String, String> attributes = dataBindingDeclaration.getAttributes();
- String model = attributes.get("model");
-
- loadedResolvers.put(model, dataBindingDeclaration);
- }
- }
-
-}
|