summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2008-12-05 09:59:09 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2008-12-05 09:59:09 +0000
commitb252a51c5e4e7550bcac4d520f8f69cb8f895851 (patch)
tree264407d92258f8f1cc7bc76891afd277162d1b2c /java
parent550a11da1d76ef3ad89ab9ab9ccccf506933670d (diff)
Models for common java artifacts and their implementations
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@723697 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r--java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaConstructor.java42
-rw-r--r--java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaElement.java92
-rw-r--r--java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaParameter.java29
-rw-r--r--java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaResource.java65
-rw-r--r--java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaConstructorImpl.java54
-rw-r--r--java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaElementImpl.java194
-rw-r--r--java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaParameterImpl.java37
-rw-r--r--java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaResourceImpl.java63
8 files changed, 576 insertions, 0 deletions
diff --git a/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaConstructor.java b/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaConstructor.java
new file mode 100644
index 0000000000..5f81353606
--- /dev/null
+++ b/java/sca/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/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaElement.java b/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaElement.java
new file mode 100644
index 0000000000..19d452d07f
--- /dev/null
+++ b/java/sca/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/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaParameter.java b/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaParameter.java
new file mode 100644
index 0000000000..d5ded915db
--- /dev/null
+++ b/java/sca/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/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaResource.java b/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/JavaResource.java
new file mode 100644
index 0000000000..38fbf75a71
--- /dev/null
+++ b/java/sca/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/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaConstructorImpl.java b/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaConstructorImpl.java
new file mode 100644
index 0000000000..36a87420ab
--- /dev/null
+++ b/java/sca/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/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaElementImpl.java b/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaElementImpl.java
new file mode 100644
index 0000000000..4ae725596f
--- /dev/null
+++ b/java/sca/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<?> cls) {
+ this.anchor = cls;
+ this.elementType = ElementType.TYPE;
+ this.type = cls;
+ this.genericType = cls;
+ this.name = cls.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/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaParameterImpl.java b/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaParameterImpl.java
new file mode 100644
index 0000000000..417644be14
--- /dev/null
+++ b/java/sca/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/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaResourceImpl.java b/java/sca/modules/implementation-pojo/src/main/java/org/apache/tuscany/sca/pojo/impl/JavaResourceImpl.java
new file mode 100644
index 0000000000..5a36a21db8
--- /dev/null
+++ b/java/sca/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;
+ }
+
+
+}