diff options
Diffstat (limited to 'branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache')
8 files changed, 802 insertions, 0 deletions
diff --git a/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/SCARuntime.java b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/SCARuntime.java new file mode 100644 index 0000000000..15b9731121 --- /dev/null +++ b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/SCARuntime.java @@ -0,0 +1,251 @@ +/* + * 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.api; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import org.osoa.sca.ComponentContext; + +/** + * SCARuntime is used to start a Tuscany SCA runtime. + */ +public abstract class SCARuntime { + public static final String DEFAULT_SYSTEM_SCDL = "META-INF/tuscany/default-system.composite"; + public static final String SYSTEM_SCDL = "system.composite"; + public static final String EXTENSION_SCDL = "META-INF/sca/extension.composite"; + public static final String SERVICE_SCDL = "META-INF/sca/service.composite"; + public static final String META_APPLICATION_SCDL = "META-INF/sca/application.composite"; + public static final String APPLICATION_SCDL = "application.composite"; + + private static SCARuntime instance; + + /** + * Read the service name from a configuration file + * + * @param classLoader + * @param name The name of the service class + * @return A class name which extends/implements the service class + * @throws IOException + */ + private static String getServiceName(ClassLoader classLoader, String name) throws IOException { + InputStream is = classLoader.getResourceAsStream("META-INF/services/" + name); + if (is == null) { + return null; + } + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(is)); + while (true) { + String line = reader.readLine(); + if (line == null) { + break; + } else if (!line.startsWith("#")) { + return line.trim(); + } + } + } finally { + if (reader != null) { + reader.close(); + } + } + return null; + } + + /** + * Returns a SCARuntime instance. If the system property "org.apache.tuscany.api.SCARuntime" is set, its value is + * used as the name of the implementation class. Otherwise, if the resource + * "META-INF/services/org.apache.tuscany.api.SCARuntime" can be loaded from the supplied classloader. Otherwise, it + * will use "org.apache.tuscany.core.bootstrap.DefaultSCARuntime" as the default. The named class is loaded from the + * supplied classloader and instantiated using its default (no-arg) constructor. + * + * @return + */ + private static SCARuntime newInstance(final ClassLoader classLoader) { + + try { + final String name = SCARuntime.class.getName(); + String className = AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { + return System.getProperty(name); + } + }); + + if (className == null) { + className = getServiceName(classLoader, name); + } + if (className == null) { + className = "org.apache.tuscany.core.bootstrap.DefaultSCARuntime"; + } + Class cls = Class.forName(className, true, classLoader); + return (SCARuntime)cls.newInstance(); // NOPMD lresende + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + /** + * Get an instance of SCA Runtime + * + * @return The instance + */ + public synchronized static SCARuntime getInstance() { // NOPMD + if (instance != null) { + return instance; + } + ClassLoader classLoader = SCARuntime.class.getClassLoader(); + instance = newInstance(classLoader); + return instance; + } + + /** + * Start the Tuscany runtime using default SCDLs + */ + public static void start() { + try { + getInstance().startup(null, null, null, null); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + /** + * Start the SCA Runtime with the given SCDLs + * + * @param system The URL for the system SCDL + * @param extensions An array of URLs for extensions + * @param application The URL for the application SCDL + */ + public static void start(URL system, URL[] extensions, URL application, String compositePath) { + try { + getInstance().startup(system, extensions, application, compositePath); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + /** + * Start the SCA Runtime with the given SCDL + * + * @param application The URL for the application SCDL + */ + public static void start(URL application, String compositePath) { + try { + getInstance().startup(null, null, application, compositePath); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + /** + * Start the SCA Runtime with the given SCDL + * + * @param compositePath The path of the application SCDL + */ + public static void start(String compositePath) { + try { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + URL applicationURL = cl.getResource(compositePath); + getInstance().startup(null, null, applicationURL, compositePath); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + /** + * Start the SCA Runtime with the given SCDL + * + * @param compositePath The path of the system SCDL + * @param compositePath The path of the application SCDL + */ + public static void start(String system, String compositePath) { + try { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + URL systemURL = cl.getResource(system); + URL applicationURL = cl.getResource(compositePath); + getInstance().startup(systemURL, null, applicationURL, compositePath); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + /** + * Get the ComponentContext by name + * + * @param componentName + * @return + */ + public static ComponentContext getComponentContext(String componentName) { + return getInstance().getContext(componentName); + } + + /** + * Get access to a system service + * + * @param serviceName + * @return + */ + protected abstract Object getSystemService(String serviceName); + + /** + * Stop the SCA Runtime + */ + public static void stop() { + try { + getInstance().shutdown(); + } catch (Exception e) { + throw new IllegalStateException(e); + } finally { + instance = null; + } + } + + /** + * Look up the ComponentContext by name + * + * @param componentName + * @return + */ + protected abstract ComponentContext getContext(String componentName); + + /** + * Start up the runtime + * + * @param system The URL of the SCDL for tuscany system composite + * @param extensions The URLs of the SCDLs for tuscany extension composites + * @param application The URL of the SCDL for the application composite + * @param compositePath The path of the application composite relative to the application URL + * @throws Exception + */ + protected abstract void startup(URL system, URL[] extensions, URL application, String compositePath) + throws Exception; + + /** + * Shutdown the runtime + * + * @throws Exception + */ + protected abstract void shutdown() throws Exception; +} diff --git a/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java new file mode 100644 index 0000000000..ad649d716f --- /dev/null +++ b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java @@ -0,0 +1,164 @@ +/* + * 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.api; + +import java.util.ArrayList; +import java.util.List; +import java.util.Collections; +import java.io.PrintWriter; + +/** + * The root checked exception for the Tuscany runtime. + * + * @version $Rev$ $Date$ + */ +public abstract class TuscanyException extends Exception { + private static final long serialVersionUID = -7847121698339635268L; + private List<String> contextStack; + private final String identifier; + + /** + * Override constructor from Exception. + * + * @see Exception + */ + public TuscanyException() { + super(); + this.identifier = null; + } + + /** + * Override constructor from Exception. + * + * @param message passed to Exception + * @see Exception + */ + public TuscanyException(String message) { + super(message); + this.identifier = null; + } + + /** + * Override constructor from Exception. + * + * @param message passed to Exception + * @param identifier additional error information referred to in the error message + * @see Exception + */ + public TuscanyException(String message, String identifier) { + super(message); + this.identifier = identifier; + } + + /** + * Override constructor from Exception. + * + * @param message passed to Exception + * @param cause passed to Exception + * @see Exception + */ + public TuscanyException(String message, Throwable cause) { + super(message, cause); + this.identifier = null; + } + + /** + * Override constructor from Exception. + * + * @param message passed to Exception + * @param identifier additional error information referred to in the error message + * @param cause passed to Exception + * @see Exception + */ + public TuscanyException(String message, String identifier, Throwable cause) { + super(message, cause); + this.identifier = identifier; + } + + /** + * Override constructor from Exception. + * + * @param cause passed to Exception + * @see Exception + */ + public TuscanyException(Throwable cause) { + super(cause); + this.identifier = null; + } + + /** + * Returns a collection of names representing the context call stack where the error occured. The top of the stack + * is the first element in the collection. + * + * @return a collection of names representing the context call stack + */ + public List<String> returnContextNames() { + if (contextStack == null) { + contextStack = new ArrayList<String>(); + } + return Collections.unmodifiableList(contextStack); + } + + /** + * Pushes a context name where an error occured onto the call stack. + * + * @param name the name of a context to push on the stack + */ + public void addContextName(String name) { + if (contextStack == null) { + contextStack = new ArrayList<String>(); + } + contextStack.add(name); + } + + /** + * Returns a string representing additional error information referred to in the error message. + * + * @return additional error information + */ + public String getIdentifier() { + return identifier; + } + + public PrintWriter appendBaseMessage(PrintWriter writer) { + if (identifier == null && contextStack == null) { + if (super.getMessage() == null) { + return writer; + } + return writer.append(super.getMessage()); + } + if (super.getMessage() != null) { + writer.append(super.getMessage()); + } + if (identifier != null) { + writer.append(" [").append(identifier).append(']'); + } + return writer; + } + + public PrintWriter appendContextStack(PrintWriter writer) { + if (contextStack != null) { + writer.append("\nContext stack trace: "); + for (int i = contextStack.size() - 1; i >= 0; i--) { + writer.append('[').append(contextStack.get(i)).append(']'); + } + } + return writer; + } +} diff --git a/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyRuntimeException.java b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyRuntimeException.java new file mode 100644 index 0000000000..fc92c57fa0 --- /dev/null +++ b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyRuntimeException.java @@ -0,0 +1,168 @@ +/* + * 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.api; + +import java.util.ArrayList; +import java.util.List; +import java.util.Collections; +import java.io.PrintWriter; + +/** + * The root unchecked exception for the Tuscany runtime. + * + * @version $Rev$ $Date$ + */ + +public abstract class TuscanyRuntimeException extends RuntimeException { + private static final long serialVersionUID = -759677431966121786L; + private List<String> contextStack; + private final String identifier; + + /** + * Override constructor from RuntimeException. + * + * @see RuntimeException + */ + public TuscanyRuntimeException() { + super(); + this.identifier = null; + } + + /** + * Override constructor from RuntimeException. + * + * @param message passed to RuntimeException + * @see RuntimeException + */ + public TuscanyRuntimeException(String message) { + super(message); + this.identifier = null; + } + + + /** + * Override constructor from Exception. + * + * @param message passed to Exception + * @param identifier additional error information referred to in the error message + * @see Exception + */ + protected TuscanyRuntimeException(String message, String identifier) { + super(message); + this.identifier = identifier; + } + + /** + * Override constructor from RuntimeException. + * + * @param message passed to RuntimeException + * @param cause passed to RuntimeException + * @see RuntimeException + */ + public TuscanyRuntimeException(String message, Throwable cause) { + super(message, cause); + this.identifier = null; + } + + + /** + * Override constructor from Exception. + * + * @param message passed to Exception + * @param identifier additional error information referred to in the error message + * @param cause passed to RuntimeException + * @see Exception + */ + protected TuscanyRuntimeException(String message, String identifier, Throwable cause) { + super(message, cause); + this.identifier = identifier; + } + + /** + * Override constructor from RuntimeException. + * + * @param cause passed to RuntimeException + * @see RuntimeException + */ + public TuscanyRuntimeException(Throwable cause) { + super(cause); + this.identifier = null; + } + + /** + * Returns a collection of names representing the context call stack where the error occured. The top of the stack + * is the first element in the collection. + * + * @return a collection of names representing the context call stack + */ + public List<String> returnContextNames() { + if (contextStack == null) { + contextStack = new ArrayList<String>(); + } + return Collections.unmodifiableList(contextStack); + } + + /** + * Pushes a context name where an error occured onto the call stack. + * + * @param name the name of a context to push on the stack + */ + public void addContextName(String name) { + if (contextStack == null) { + contextStack = new ArrayList<String>(); + } + contextStack.add(name); + } + + /** + * Returns a string representing additional error information referred to in the error message. + * + * @return additional error information + */ + public String getIdentifier() { + return identifier; + } + + public PrintWriter appendBaseMessage(PrintWriter writer) { + if (identifier == null && contextStack == null) { + if (super.getMessage() == null) { + return writer; + } + return writer.append(super.getMessage()); + } + if (super.getMessage() != null) { + writer.append(super.getMessage()); + } + if (identifier != null) { + writer.append(" [").append(identifier).append(']'); + } + return writer; + } + + public PrintWriter appendContextStack(PrintWriter writer) { + if (contextStack != null) { + writer.append("Context stack trace: "); + for (int i = contextStack.size() - 1; i >= 0; i--) { + writer.append('[').append(contextStack.get(i)).append(']'); + } + } + return writer; + } + +} diff --git a/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataType.java b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataType.java new file mode 100644 index 0000000000..33e67a60ae --- /dev/null +++ b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataType.java @@ -0,0 +1,45 @@ +/* + * 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.api.annotation; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Used to demarcate expected data types for an operation + * + * @version $Rev$ $Date$ + */ +@Target({TYPE, METHOD, FIELD, PARAMETER}) +@Retention(RUNTIME) +public @interface DataType { + + /** + * Returns the unique name of the data binding + * @return the unique name of the data binding + */ + String name(); + +} diff --git a/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/IDLMapping.java b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/IDLMapping.java new file mode 100644 index 0000000000..e8c88b6176 --- /dev/null +++ b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/IDLMapping.java @@ -0,0 +1,51 @@ +/* + * 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.api.annotation; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Annotation that can be applied to interfaces or methods to provide IDL mapping metadata + * + * @version $Rev$ $Date$ + */ +@Target({METHOD, TYPE}) +@Retention(RUNTIME) +public @interface IDLMapping { + + /** + * The name of the databinding for the wrapper + */ + String dataBinding() default ""; + + /** + * To indicate if the java interface/method is generated from a WSDL using wrapper style. + * + * @see javax.xml.ws.RequestWrapper + * @see javax.xml.ws.RequestWrapper + * + * @return + */ + boolean wrapperStyle() default true; +} diff --git a/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/LogLevel.java b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/LogLevel.java new file mode 100644 index 0000000000..83c5df26d9 --- /dev/null +++ b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/LogLevel.java @@ -0,0 +1,40 @@ +/* + * 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.api.annotation; + +import static java.lang.annotation.ElementType.METHOD; +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Target; + +/** + * Annotation that can be applied to methods in a monitoring interface to indicate to logging frameworks the severity of + * the event. + * + * @version $Rev$ $Date$ + */ +@Target({METHOD}) +@Retention(RUNTIME) +public @interface LogLevel { + + /** + * The log level as specified by {@link java.util.logging.Level}. + */ + @SuppressWarnings({"JavaDoc"}) String value(); +} diff --git a/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Monitor.java b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Monitor.java new file mode 100644 index 0000000000..dea9489e5b --- /dev/null +++ b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Monitor.java @@ -0,0 +1,34 @@ +/* + * 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.api.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * A system annotation to inject a monitor + * + * @version $Rev$ $Date$ + */ +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Monitor { +} diff --git a/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Resource.java b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Resource.java new file mode 100644 index 0000000000..a7158ab6b8 --- /dev/null +++ b/branches/sca-java-integration/sca/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Resource.java @@ -0,0 +1,49 @@ +/* + * 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.api.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation used to indicate a resource should be provided to an implementation by the runtime. + * + * @version $Rev$ $Date$ + */ +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Resource { + + /** + * Denotes the name of the resource declared by the implementation. + */ + String name() default ""; + + /** + * Denotes if the resource is optional + */ + boolean optional() default false; + + /** + * Denotes the default name of the resource provided by the runtime environment. + */ + String mappedName() default ""; +} |