Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.implementation.spring;
 
 import java.net.URL;
 import java.util.List;
 import java.util.Map;
 
 
Represents a Spring implementation.

Version:
$Rev: 987670 $ $Date: 2010-08-21 00:42:07 +0100 (Sat, 21 Aug 2010) $
 
 public class SpringImplementation extends ImplementationImpl implements ImplementationExtensible {
     public final static QName TYPE = new QName("implementation.spring");
     // The location attribute which points to the Spring application-context XML file
     private String location;
     // The application-context file as a Spring Resource
     private List<URLresource;
     private ComponentType componentType;
     // Mapping of Services to Beans
     private Map<StringSpringBeanElementserviceMap;
     // Mapping of property names to Java class
     private Map<StringClass<?>> propertyMap;
     // List of unresolved bean property references
     private Map<StringReferenceunresolvedBeanRef;
     private ClassLoader classLoader;
 
     public SpringImplementation() {
         super();
         this. = null;
         this. = null;
         setUnresolved(true);
          = new HashMap<StringSpringBeanElement>();
          = new HashMap<StringClass<?>>();
          = new HashMap<StringReference>();
     } // end method SpringImplementation
 
     /* Returns the location attribute for this Spring implementation */
     public String getLocation() {
         return ;
     }

    
Sets the location attribute for this Spring implementation location - a URI to the Spring application-context file
 
     public void setLocation(String location) {
         this. = location;
         return;
     }
 
     public void setResource(List<URLresource) {
         this. = resource;
     }
 
     public List<URLgetResource() {
         return ;
     }
 
     /*
      * Returns the componentType for this Spring implementation
      */
     public ComponentType getComponentType() {
         return ;
     }
 
     /*
      * Sets the componentType for this Spring implementation
      */
    public void setComponentType(ComponentType componentType) {
        this. = componentType;
    }
    @Override
    public List<ServicegetServices() {
        return .getServices();
    }
    @Override
    public List<ReferencegetReferences() {
        return .getReferences();
    }
    @Override
    public List<PropertygetProperties() {
        return .getProperties();
    }

    
Returns the Spring Bean which implements a particular service

Parameters:
service the service
Returns:
the bean which implements the service, as a SpringBeanElement
    public SpringBeanElement getBeanFromService(Service service) {
        SpringBeanElement theBean = .get(service.getName());
        return theBean;
    }

    
Sets the mapping from a service to the Spring Bean that implements the service

Parameters:
service the service
theBean a SpringBeanElement for the Bean implementing the service
    public void setBeanForService(Service serviceSpringBeanElement theBean) {
        .put(service.getName(), theBean);
    }

    
Add a mapping from a SCA property name to a Java class for the property

Parameters:
propertyName
propertyClass
    public void setPropertyClass(String propertyNameClass<?> propertyClass) {
        if (propertyName == null || propertyClass == null)
            return;
        .put(propertyNamepropertyClass);
        return;
    } // end method setPropertyClass

    
Gets the Java Class for an SCA property

Parameters:
propertyName - the property name
Returns:
- a Class object for the type of the property
    public Class<?> getPropertyClass(String propertyName) {
        return .get(propertyName);
    } // end method getPropertyClass
    public void setUnresolvedBeanRef(String refNameReference reference) {
        if (refName == null || reference == null)
            return;
        .put(refNamereference);
        return;
    } // end method setUnresolvedBeanRef
    public Reference getUnresolvedBeanRef(String refName) {
        return .get(refName);
    } // end method getUnresolvedBeanRef

    
Use preProcess to validate and map the references and properties dynamically
    public void build(Component component) {
        for (Reference reference : component.getReferences()) {
            if (.containsKey(reference.getName())) {
                Reference ref = .get(reference.getName());
                .getReferences().add(createReference(referenceref.getInterfaceContract()));
                .remove(reference.getName());
            }
        }
        for (Property property : component.getProperties()) {
            if (.containsKey(property.getName())) {
                .getProperties().add(createProperty(property));
                this.setPropertyClass(property.getName(), property.getClass());
                .remove(property.getName());
            }
        }
    }
    protected Reference createReference(Reference referenceInterfaceContract interfaze) {
        Reference newReference;
        try {
            newReference = (Reference)reference.clone();
            if (newReference.getInterfaceContract() == null)
                newReference.setInterfaceContract(interfaze);
        } catch (CloneNotSupportedException e) {
            throw new AssertionError(e); // should not ever happen
        }
        return newReference;
    }
    protected Property createProperty(Property property) {
        Property newProperty;
        try {
            newProperty = (Property)property.clone();
        } catch (CloneNotSupportedException e) {
            throw new AssertionError(e); // should not ever happen
        }
        return newProperty;
    }
    public ClassLoader getClassLoader() {
        return ;
    }
    public void setClassLoader(ClassLoader classLoader) {
        this. = classLoader;
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + (( == null) ? 0 : .hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!super.equals(obj)) {
            return false;
        }
        if (!(obj instanceof SpringImplementation)) {
            return false;
        }
        SpringImplementation other = (SpringImplementation)obj;
        if ( == null) {
            if (other.location != null) {
                return false;
            }
        } else if (!.equals(other.location)) {
            return false;
        }
        return true;
    }
    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("SpringImplementation [location=").append().append(", resource=").append()
            .append("]");
        return builder.toString();
    }
New to GrepCode? Check out our FAQ X