diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-12 00:43:48 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-12 00:43:48 +0000 |
commit | 9425990f532b1152c2d73db96c0f07ef5216a3d1 (patch) | |
tree | a8986fc31f96eb02484a0ae9d1c14cfa788e30ac /sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca | |
parent | 40523f9c6cb1f7a785c2dbd2466dc410ae6ddf66 (diff) |
Moving 2.x contribs
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835178 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca')
10 files changed, 732 insertions, 0 deletions
diff --git a/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaConstructor.java b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaConstructor.java new file mode 100644 index 0000000000..5f81353606 --- /dev/null +++ b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaConstructor.java @@ -0,0 +1,42 @@ +/* + * 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.pojo; + +import java.lang.reflect.Constructor; + + +/** + * Hold injection information for the constructor used to instantiate a + * component implementation instance + * + * @version $Rev$ $Date$ + */ +public interface JavaConstructor<T> { + + /** + * @return the constructor + */ + Constructor<T> getConstructor(); + + /** + * @return the parameters + */ + JavaParameter[] getParameters(); + +}
\ No newline at end of file diff --git a/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaElement.java b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaElement.java new file mode 100644 index 0000000000..19d452d07f --- /dev/null +++ b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaElement.java @@ -0,0 +1,92 @@ +/* + * 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.pojo; + +import java.lang.annotation.Annotation; +import java.lang.annotation.ElementType; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Type; + + +/** + * This class represents a java element such as a Package, Class, Constructor, + * Field, Method or Parameter. + * + * @version $Rev$ $Date$ + */ +public interface JavaElement { + + /** + * @return the anchor + */ + AnnotatedElement getAnchor(); + + /** + * @return the elementType + */ + ElementType getElementType(); + + /** + * @return the genericType + */ + Type getGenericType(); + + /** + * @return the index + */ + int getIndex(); + + /** + * @return the type + */ + Class<?> getType(); + + /** + * @return the annotations + */ + Annotation[] getAnnotations(); + + /** + * Return a given annotation + * @param annotationType the annotation type + * @return the annotation + */ + <T extends Annotation> T getAnnotation(Class<T> annotationType); + + /** + * @return the name + */ + String getName(); + + /** + * @param name the name to set + */ + void setName(String name); + + /** + * @return the classifier + */ + Class<? extends Annotation> getClassifer(); + + /** + * @param classifer the classifier to set + */ + void setClassifer(Class<? extends Annotation> classifer); + +}
\ No newline at end of file diff --git a/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaFactory.java b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaFactory.java new file mode 100644 index 0000000000..28375c86f8 --- /dev/null +++ b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaFactory.java @@ -0,0 +1,82 @@ +/* + * 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.pojo; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +/** + * Factory for the Java model used during introspection of java class/interfaces + * + * @version $Rev$ $Date$ + */ + +public interface JavaFactory { + + /** + * Create a model representing a java constructor + * @param clazz + * @return the java constructor + */ + JavaConstructor<?> createJavaConstructor(Constructor<?> constructor); + + /** + * Create model representing a java class + * @param clazz the class + * @return the java element representing the class + */ + JavaElement createJavaElement(Class<?> clazz); + + /** + * Create a model representing a java property + * @param field the property + * @return the java element representing the property + */ + JavaElement createJavaElement(Field field); + + /** + * Create a model representing a java constructor + * @param constructor the constructor + * @param index the constructor position + * @return the java element representing the constructor + */ + JavaElement createJavaElement(Constructor<?> constructor, int index); + + /** + * Create a model representing a java method + * @param method the method + * @param index the method position + * @return the java element representing the constructor + */ + JavaElement createJavaElement(Method method, int index); + + /** + * Create a model representing a java parameter + * @return the parameter + */ + JavaParameter createJavaParameter(Constructor<?> constructor, int index); + + /** + * Create a model representing a java resource + * @return + */ + JavaResource createJavaResource(JavaElement element); + +}
\ No newline at end of file diff --git a/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaParameter.java b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaParameter.java new file mode 100644 index 0000000000..d5ded915db --- /dev/null +++ b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaParameter.java @@ -0,0 +1,29 @@ +/* + * 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.pojo; + +/** + * This class represents a java element such as a Package, Class, Constructor, + * Field, Method or Parameter. + * + * @version $Rev$ $Date$ + */ +public interface JavaParameter extends JavaElement { + +}
\ No newline at end of file diff --git a/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaResource.java b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaResource.java new file mode 100644 index 0000000000..38fbf75a71 --- /dev/null +++ b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaResource.java @@ -0,0 +1,65 @@ +/* + * 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.pojo; + + +/** + * A resource dependency declared by a Java component implementation + * + * @version $Rev$ $Date$ + */ +public interface JavaResource { + + /** + * The name of the resource + * + * @return the name of the resource + */ + String getName(); + + /** + * Returns the URI of the resource + * + * @return the URI of the resource + */ + String getMappedName(); + + /** + * Sets the resource URI + */ + void setMappedName(String mappedName); + + /** + * If true, the resource is optional + * + * @return true if the resource is optional + */ + boolean isOptional(); + + /** + * Sets whether the resource is optional + */ + void setOptional(boolean optional); + + /** + * @return the element + */ + JavaElement getElement(); + +}
\ No newline at end of file diff --git a/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaConstructorImpl.java b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaConstructorImpl.java new file mode 100644 index 0000000000..36a87420ab --- /dev/null +++ b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaConstructorImpl.java @@ -0,0 +1,54 @@ +/* + * 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.pojo.impl; + +import java.lang.reflect.Constructor; + +import org.apache.tuscany.sca.pojo.JavaConstructor; + + +/** + * Hold injection information for the constructor used to instantiate a + * component implementation instance + * + * @version $Rev$ $Date$ + */ +public class JavaConstructorImpl<T> implements JavaConstructor<T> { + private Constructor<T> constructor; + private JavaParameterImpl[] parameters; + + public JavaConstructorImpl(Constructor<T> constructor) { + this.constructor = constructor; + int size = constructor.getParameterTypes().length; + parameters = new JavaParameterImpl[size]; + for (int i = 0; i < size; i++) { + parameters[i] = new JavaParameterImpl(constructor, i); + } + } + + + public Constructor<T> getConstructor() { + return constructor; + } + + + public JavaParameterImpl[] getParameters() { + return parameters; + } +} diff --git a/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaElementImpl.java b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaElementImpl.java new file mode 100644 index 0000000000..fc3ca3238f --- /dev/null +++ b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaElementImpl.java @@ -0,0 +1,194 @@ +/* + * 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.pojo.impl; + +import java.lang.annotation.Annotation; +import java.lang.annotation.ElementType; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Type; + +import org.apache.tuscany.sca.pojo.JavaElement; + +/** + * This class represents a java element such as a Package, Class, Constructor, + * Field, Method or Parameter. + * + * @version $Rev$ $Date$ + */ +public class JavaElementImpl implements JavaElement { + private AnnotatedElement anchor; + private ElementType elementType; + private Class<?> type; + private Type genericType; + private int index = -1; + private String name; + private Class<? extends Annotation> classifer; + + public JavaElementImpl(Class<?> clazz) { + this.anchor = clazz; + this.elementType = ElementType.TYPE; + this.type = clazz; + this.genericType = clazz; + this.name = clazz.getName(); + } + + public JavaElementImpl(Field field) { + this.anchor = field; + this.elementType = ElementType.FIELD; + this.type = field.getType(); + this.genericType = field.getGenericType(); + this.name = field.getName(); + } + + public JavaElementImpl(Constructor<?> constructor, int index) { + this.anchor = constructor; + this.elementType = ElementType.PARAMETER; + this.type = constructor.getParameterTypes()[index]; + this.genericType = constructor.getGenericParameterTypes()[index]; + this.index = index; + this.name = ""; + } + + public JavaElementImpl(Method method, int index) { + this.anchor = method; + this.elementType = ElementType.PARAMETER; + this.type = method.getParameterTypes()[index]; + this.genericType = method.getGenericParameterTypes()[index]; + this.index = index; + this.name = ""; + } + + /** + * For testing purpose + * + * @param name + * @param type + * @param classifer TODO + * @param elementType + */ + public JavaElementImpl(String name, Class<?> type, Class<? extends Annotation> classifer) { + super(); + this.type = type; + this.name = name; + this.classifer = classifer; + } + + public AnnotatedElement getAnchor() { + return anchor; + } + + public ElementType getElementType() { + return elementType; + } + + public Type getGenericType() { + return genericType; + } + + public int getIndex() { + return index; + } + + public Class<?> getType() { + return type; + } + + public Annotation[] getAnnotations() { + if (elementType == ElementType.PARAMETER) { + if (anchor instanceof Method) { + // We only care about the method-level annotations + return ((Method)anchor).getAnnotations(); + } + if (anchor instanceof Constructor) { + return ((Constructor<?>)anchor).getParameterAnnotations()[index]; + } + } + return anchor.getAnnotations(); + } + + public <T extends Annotation> T getAnnotation(Class<T> annotationType) { + for (Annotation a : getAnnotations()) { + if (a.annotationType() == annotationType) { + return annotationType.cast(a); + } + } + return null; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Class<? extends Annotation> getClassifer() { + return classifer; + } + + public void setClassifer(Class<? extends Annotation> classifer) { + this.classifer = classifer; + } + + + @Override + public String toString() { + return anchor.toString() + (elementType == ElementType.PARAMETER ? "[" + index + "]" : ""); + } + + @Override + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((anchor == null) ? 0 : anchor.hashCode()); + result = PRIME * result + index; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final JavaElementImpl other = (JavaElementImpl)obj; + if (anchor == null) { + if (other.anchor != null) { + return false; + } + } else if (!anchor.equals(other.anchor)) { + return false; + } + if (index != other.index) { + return false; + } + return true; + } + +} diff --git a/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaFactoryImpl.java b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaFactoryImpl.java new file mode 100644 index 0000000000..d1b7d4c5ad --- /dev/null +++ b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaFactoryImpl.java @@ -0,0 +1,74 @@ +/* + * 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.pojo.impl; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.pojo.JavaConstructor; +import org.apache.tuscany.sca.pojo.JavaElement; +import org.apache.tuscany.sca.pojo.JavaFactory; +import org.apache.tuscany.sca.pojo.JavaParameter; +import org.apache.tuscany.sca.pojo.JavaResource; + +/** + * Factory for the Java model used during introspection of java class/interfaces + * + * @version $Rev$ $Date$ + */ + +public class JavaFactoryImpl implements JavaFactory { + + public void JavaFactory() { + + } + + public JavaConstructor<?> createJavaConstructor(Constructor<?> constructor){ + return new JavaConstructorImpl(constructor); + } + + public JavaElement createJavaElement(Class<?> clazz) { + return new JavaElementImpl(clazz); + } + + public JavaElement createJavaElement(Field field){ + return new JavaElementImpl(field); + + } + + public JavaElement createJavaElement(Constructor<?> constructor, int index) { + return new JavaElementImpl(constructor, index); + + } + + public JavaElement createJavaElement(Method method, int index) { + return new JavaElementImpl(method, index); + } + + public JavaParameter createJavaParameter(Constructor<?> constructor, int index) { + return new JavaParameterImpl(constructor, index); + } + + public JavaResource createJavaResource(JavaElement element) { + return new JavaResourceImpl(element); + } + +} + diff --git a/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaParameterImpl.java b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaParameterImpl.java new file mode 100644 index 0000000000..417644be14 --- /dev/null +++ b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaParameterImpl.java @@ -0,0 +1,37 @@ +/* + * 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.pojo.impl; + +import java.lang.reflect.Constructor; + +import org.apache.tuscany.sca.pojo.JavaParameter; + +/** + * @version $Rev$ $Date$ + */ +public class JavaParameterImpl extends JavaElementImpl implements JavaParameter { + /** + * @param constructor + * @param index + */ + public JavaParameterImpl(Constructor<?> constructor, int index) { + super(constructor, index); + } +} diff --git a/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaResourceImpl.java b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaResourceImpl.java new file mode 100644 index 0000000000..5a36a21db8 --- /dev/null +++ b/sca-java-2.x/contrib/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaResourceImpl.java @@ -0,0 +1,63 @@ +/* + * 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.pojo.impl; + +import org.apache.tuscany.sca.pojo.JavaElement; +import org.apache.tuscany.sca.pojo.JavaResource; + +/** + * A resource dependency declared by a Java component implementation + * + * @version $Rev$ $Date$ + */ +public class JavaResourceImpl implements JavaResource { + private JavaElement element; + private String mappedName; + private boolean optional; + + public JavaResourceImpl(JavaElement element) { + this.element = element; + } + + public String getName() { + return element.getName(); + } + + public String getMappedName() { + return mappedName; + } + + public void setMappedName(String mappedName) { + this.mappedName = mappedName; + } + + public boolean isOptional() { + return optional; + } + + public void setOptional(boolean optional) { + this.optional = optional; + } + + public JavaElement getElement() { + return element; + } + + +} |