diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-20 23:53:35 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-20 23:53:35 +0000 |
commit | a3c48da9bb8971497d414f86e352123d95b9c3da (patch) | |
tree | fdf0f3636b65946c061c8b2e89d657b488be274e /sca-java-2.x/trunk/modules/policy-logging/src/main | |
parent | cc7496466097c3cb8e793ebf3e332b025705aaa7 (diff) |
Moving 2.x trunk
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@882795 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/policy-logging/src/main')
14 files changed, 838 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/Logging.java b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/Logging.java new file mode 100644 index 0000000000..4bed9520ab --- /dev/null +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/Logging.java @@ -0,0 +1,46 @@ +/* + * 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.policy.logging; + +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.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.apache.tuscany.sca.assembly.Base; +import org.oasisopen.sca.annotation.Intent; +import org.oasisopen.sca.annotation.Qualifier; + +@Inherited +@Target({TYPE, FIELD, METHOD, PARAMETER}) +@Retention(RUNTIME) +@Intent(Logging.LOGGING) + +public @interface Logging { + String LOGGING = "{"+Base.SCA11_TUSCANY_NS + "}logging"; + + @Qualifier + String[] value() default ""; +} diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java new file mode 100644 index 0000000000..66a0ba2b51 --- /dev/null +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java @@ -0,0 +1,48 @@ +/* + * 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.policy.logging.jdk; + +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.provider.BasePolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev$ $Date$ + */ +public class JDKLoggingImplementationPolicyProvider extends BasePolicyProvider<JDKLoggingPolicy> { + + public JDKLoggingImplementationPolicyProvider(RuntimeComponent component) { + super(JDKLoggingPolicy.class, component); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation) + */ + public PhasedInterceptor createInterceptor(Operation operation) { + List<JDKLoggingPolicy> policies = findPolicies(); + return policies.isEmpty() ? null : new JDKLoggingPolicyInterceptor(subject, getContext(), operation, + policies, Phase.IMPLEMENTATION_POLICY); + } + +} diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicy.java b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicy.java new file mode 100644 index 0000000000..6e1bad67c1 --- /dev/null +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicy.java @@ -0,0 +1,97 @@ +/* + * 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.policy.logging.jdk; + +import java.util.logging.Level; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Base; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class JDKLoggingPolicy { + static final String SCA11_NS = Base.SCA11_NS; + static final String SCA11_TUSCANY_NS = Base.SCA11_TUSCANY_NS; + static final QName JDK_LOGGING_POLICY_QNAME = new QName(SCA11_TUSCANY_NS, "jdkLogger"); + + private String loggerName; + private String resourceBundleName; + private Level logLevel; + private boolean useParentHandlers = false; + + public String getLoggerName() { + return loggerName; + } + + public void setLoggerName(String loggerName) { + this.loggerName = loggerName; + } + + public Level getLogLevel() { + return logLevel; + } + + public void setLogLevel(Level logLevel) { + this.logLevel = logLevel; + } + + public String getResourceBundleName() { + return resourceBundleName; + } + + public void setResourceBundleName(String resourceBundleName) { + this.resourceBundleName = resourceBundleName; + } + + public boolean isUseParentHandlers() { + return useParentHandlers; + } + + public void setUseParentHandlers(boolean useParentHandlers) { + this.useParentHandlers = useParentHandlers; + } + + public QName getSchemaName() { + return JDK_LOGGING_POLICY_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + @Override + public String toString() { + return "JDKLoggingPolicy [logLevel=" + logLevel + + ", loggerName=" + + loggerName + + ", resourceBundleName=" + + resourceBundleName + + ", useParentHandlers=" + + useParentHandlers + + "]"; + } +} diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyBuilder.java b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyBuilder.java new file mode 100644 index 0000000000..11957df752 --- /dev/null +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyBuilder.java @@ -0,0 +1,80 @@ +/* + * 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.policy.logging.jdk; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; +import org.apache.tuscany.sca.assembly.builder.PolicyBuilder; +import org.apache.tuscany.sca.policy.PolicyExpression; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySubject; + +/** + * + */ +public class JDKLoggingPolicyBuilder implements PolicyBuilder<JDKLoggingPolicy> { + + public boolean build(Endpoint endpoint, BuilderContext context) { + List<JDKLoggingPolicy> polices = getPolicies(endpoint); + System.out.println(endpoint + ": " + polices); + return true; + } + + public boolean build(EndpointReference endpointReference, BuilderContext context) { + List<JDKLoggingPolicy> polices = getPolicies(endpointReference); + System.out.println(endpointReference + ": " + polices); + return true; + } + + public boolean build(Component component, Implementation implementation, BuilderContext context) { + List<JDKLoggingPolicy> polices = getPolicies(implementation); + System.out.println(implementation + ": " + polices); + return true; + } + + public QName getPolicyType() { + return JDKLoggingPolicy.JDK_LOGGING_POLICY_QNAME; + } + + private List<JDKLoggingPolicy> getPolicies(PolicySubject subject) { + List<JDKLoggingPolicy> polices = new ArrayList<JDKLoggingPolicy>(); + for (PolicySet ps : subject.getPolicySets()) { + for (PolicyExpression exp : ps.getPolicies()) { + if (getPolicyType().equals(exp.getName())) { + polices.add((JDKLoggingPolicy)exp.getPolicy()); + } + } + } + return polices; + } + + public boolean build(EndpointReference endpointReference, Endpoint endpoint, BuilderContext context) { + return true; + } + +} diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyInterceptor.java b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyInterceptor.java new file mode 100644 index 0000000000..b6c83a804a --- /dev/null +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyInterceptor.java @@ -0,0 +1,171 @@ +/* + * 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.policy.logging.jdk; + +import java.util.List; +import java.util.logging.ConsoleHandler; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.policy.PolicySubject; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.1/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class JDKLoggingPolicyInterceptor implements PhasedInterceptor { + public static final String loggingPolicy = "JDKLoggingPolicy"; + public static final QName policySetQName = new QName(JDKLoggingPolicy.SCA11_TUSCANY_NS, loggingPolicy); + private Logger logger = null; + + private Invoker next; + private Operation operation; + private List<JDKLoggingPolicy> policies; + private PolicySubject subject; + private String context; + private String phase; + + public JDKLoggingPolicyInterceptor(PolicySubject subject, + String context, + Operation operation, + List<JDKLoggingPolicy> policies, + String phase) { + super(); + this.operation = operation; + this.policies = policies; + this.subject = subject; + this.phase = phase; + this.context = getContext(); + init(); + } + + private String getContext() { + if (subject instanceof Endpoint) { + Endpoint endpoint = (Endpoint)subject; + return endpoint.getURI(); + } else if (subject instanceof EndpointReference) { + EndpointReference endpointReference = (EndpointReference)subject; + return endpointReference.getURI(); + } else if (subject instanceof Component) { + Component component = (Component)subject; + return component.getURI(); + } + return null; + } + + private void init() { + JDKLoggingPolicy policy = policies.get(0); + logger = Logger.getLogger(policy.getLoggerName()); + logger.setLevel(policy.getLogLevel()); + logger.setUseParentHandlers(policy.isUseParentHandlers()); + + boolean found = false; + for (Handler handler : logger.getHandlers()) { + if (handler instanceof ConsoleHandler) { + found = true; + break; + } + } + + if (!found) { + ConsoleHandler consoleHandler = new ConsoleHandler(); + consoleHandler.setLevel(Level.ALL); + logger.addHandler(consoleHandler); + } + + if (logger.isLoggable(Level.FINE)) { + logger.logp(Level.FINE, context, "", "Intents: {0}", subject.getRequiredIntents()); + logger.logp(Level.FINE, context, "", "PolicySets: {0}", subject.getPolicySets()); + } + } + + public Message invoke(Message msg) { + if (logger == null) { + return getNext().invoke(msg); + } + logger.logp(Level.INFO, context, "", "Invoking operation - " + operation.getName()); + Object msgBody = msg.getBody(); + if (msgBody instanceof Object[]) { + + if (logger.isLoggable(Level.FINE)) { + StringBuffer sb = new StringBuffer(); + if (msgBody == null) { + sb.append(""); + } else { + Object[] args = (Object[])msgBody; + for (int i = 0; i < args.length; i++) { + sb.append(args[i]); + if (i != args.length - 1) { + sb.append(", "); + } + } + } + + Object[] logParams = new Object[] {operation.getName(), sb.toString()}; + logger.logp(Level.FINE, context, "", "Invoking operation {0} with arguments {1}", logParams); + } + } + + Message responseMsg = null; + try { + responseMsg = getNext().invoke(msg); + return responseMsg; + } catch (RuntimeException e) { + logger.logp(Level.SEVERE, context, "", "Exception thrown from operation - " + operation.getName(), e); + throw e; + } finally { + if (responseMsg != null) { + logger.logp(Level.INFO, context, "", "Returned from operation - " + operation.getName()); + if (logger.isLoggable(Level.FINE)) { + Object[] logParams = new Object[] {operation.getName(), responseMsg.getBody()}; + logger.logp(Level.FINE, + context, + "", + "Returning from operation {0} with return value {1}", + logParams); + } + } + } + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public String getPhase() { + return phase; + } + +} diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyProcessor.java b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyProcessor.java new file mode 100644 index 0000000000..6ca5732e7a --- /dev/null +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyProcessor.java @@ -0,0 +1,135 @@ +/* + * 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.policy.logging.jdk; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.logging.Level; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; + +/** + * + * @version $Rev$ $Date$ + */ +public class JDKLoggingPolicyProcessor implements StAXArtifactProcessor<JDKLoggingPolicy> { + private static final QName JDK_LOGGING_POLICY_QNAME = new QName(JDKLoggingPolicy.SCA11_TUSCANY_NS, "jdkLogger"); + private static final String LOG_LEVEL = "logLevel"; + private static final String RESOURCE_BUNDLE = "resourceBundle"; + private static final String USE_PARENT_HANDLERS = "useParentHandlers"; + + public QName getArtifactType() { + return JDK_LOGGING_POLICY_QNAME; + } + + public JDKLoggingPolicyProcessor(FactoryExtensionPoint modelFactories) { + } + + + public JDKLoggingPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + JDKLoggingPolicy policy = new JDKLoggingPolicy(); + int event = reader.getEventType(); + QName name = null; + + + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if ( name.equals(JDK_LOGGING_POLICY_QNAME) ) { + String loggerName = reader.getAttributeValue(null, "name"); + policy.setLoggerName(loggerName); + } else if ( LOG_LEVEL.equals(name.getLocalPart()) ) { + policy.setLogLevel(Level.parse(reader.getElementText())); + } else if ( RESOURCE_BUNDLE.equals(name.getLocalPart()) ) { + policy.setResourceBundleName(reader.getElementText()); + } else if ( USE_PARENT_HANDLERS.equals(name.getLocalPart()) ) { + policy.setUseParentHandlers(Boolean.getBoolean(reader.getElementText())); + } + break; + } + } + + if ( event == END_ELEMENT ) { + if ( JDK_LOGGING_POLICY_QNAME.equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(JDKLoggingPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, + XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + JDK_LOGGING_POLICY_QNAME.getLocalPart(), + JDK_LOGGING_POLICY_QNAME.getNamespaceURI()); + writer.writeNamespace("tuscany", JDKLoggingPolicy.SCA11_TUSCANY_NS); + + if (policy.getLoggerName() != null) { + writer.writeAttribute("name", policy.getLoggerName()); + } + if ( policy.getLogLevel() != null ) { + writer.writeStartElement(prefix, + LOG_LEVEL, + JDK_LOGGING_POLICY_QNAME.getNamespaceURI()); + writer.writeCharacters(policy.getLogLevel().getLocalizedName()); + writer.writeEndElement(); + } + + if ( policy.getResourceBundleName() != null ) { + writer.writeStartElement(prefix, + RESOURCE_BUNDLE, + JDK_LOGGING_POLICY_QNAME.getNamespaceURI()); + writer.writeCharacters(policy.getResourceBundleName()); + writer.writeEndElement(); + } + + writer.writeEndElement(); + } + + public Class<JDKLoggingPolicy> getModelType() { + return JDKLoggingPolicy.class; + } + + public void resolve(JDKLoggingPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { + + } + +} diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyProviderFactory.java b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyProviderFactory.java new file mode 100644 index 0000000000..62bf06475b --- /dev/null +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyProviderFactory.java @@ -0,0 +1,68 @@ +/* + * 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.policy.logging.jdk; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev$ $Date$ + */ +public class JDKLoggingPolicyProviderFactory implements PolicyProviderFactory<JDKLoggingPolicy> { + private ExtensionPointRegistry registry; + + public JDKLoggingPolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createImplementationPolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.assembly.Implementation) + */ + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component) { + return new JDKLoggingImplementationPolicyProvider(component); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createReferencePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createReferencePolicyProvider(EndpointReference endpointReference) { + return new JDKLoggingReferencePolicyProvider(endpointReference); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createServicePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentService, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createServicePolicyProvider(Endpoint endpoint) { + return new JDKLoggingServicePolicyProvider(endpoint); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class<JDKLoggingPolicy> getModelType() { + return JDKLoggingPolicy.class; + } + +} diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java new file mode 100644 index 0000000000..80867f57de --- /dev/null +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.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.sca.policy.logging.jdk; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.provider.BasePolicyProvider; + +/** + * @version $Rev$ $Date$ + */ +public class JDKLoggingReferencePolicyProvider extends BasePolicyProvider<JDKLoggingPolicy> { + + public JDKLoggingReferencePolicyProvider(EndpointReference endpointReference) { + super(JDKLoggingPolicy.class, endpointReference); + } + + public PhasedInterceptor createInterceptor(Operation operation) { + List<JDKLoggingPolicy> policies = findPolicies(); + return policies.isEmpty() ? null : new JDKLoggingPolicyInterceptor(subject, getContext(), operation, + policies, Phase.REFERENCE_POLICY); + } + +} diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java new file mode 100644 index 0000000000..99f0563603 --- /dev/null +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java @@ -0,0 +1,44 @@ +/* + * 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.policy.logging.jdk; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.provider.BasePolicyProvider; + +/** + * @version $Rev$ $Date$ + */ +public class JDKLoggingServicePolicyProvider extends BasePolicyProvider<JDKLoggingPolicy> { + + public JDKLoggingServicePolicyProvider(Endpoint endpoint) { + super(JDKLoggingPolicy.class, endpoint); + } + + public PhasedInterceptor createInterceptor(Operation operation) { + List<JDKLoggingPolicy> policies = findPolicies(); + return policies.isEmpty() ? null : new JDKLoggingPolicyInterceptor(subject, getContext(), operation, policies, Phase.SERVICE_POLICY); + } + +} diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.PolicyBuilder b/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.PolicyBuilder new file mode 100644 index 0000000000..f1fbc54a7a --- /dev/null +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.PolicyBuilder @@ -0,0 +1,17 @@ +# 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.
+org.apache.tuscany.sca.policy.logging.jdk.JDKLoggingPolicyBuilder;qname=http://tuscany.apache.org/xmlns/sca/1.1#jdkLogger
diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..9d0a8fb67f --- /dev/null +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,20 @@ +# 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. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.policy.logging.jdk.JDKLoggingPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#jdkLogger,model=org.apache.tuscany.sca.policy.logging.jdk.JDKLoggingPolicy +
diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions b/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions new file mode 100644 index 0000000000..bb7aed2087 --- /dev/null +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions @@ -0,0 +1,17 @@ +# 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.
+org/apache/tuscany/sca/policy/logging/definitions.xml
diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory b/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory new file mode 100644 index 0000000000..b9bb454550 --- /dev/null +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory @@ -0,0 +1,20 @@ +# 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.
+
+# Implementation class for the policy extension
+org.apache.tuscany.sca.policy.logging.jdk.JDKLoggingPolicyProviderFactory;model=org.apache.tuscany.sca.policy.logging.jdk.JDKLoggingPolicy
+
diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/org/apache/tuscany/sca/policy/logging/definitions.xml b/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/org/apache/tuscany/sca/policy/logging/definitions.xml new file mode 100644 index 0000000000..95c976ba49 --- /dev/null +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/resources/org/apache/tuscany/sca/policy/logging/definitions.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + * 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. +--> +<definitions xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" + targetNamespace="http://tuscany.apache.org/xmlns/sca/1.1"> + + <!-- Policy Intents Defined by the SCA Runtime --> + <intent name="logging" constrains="implementation binding"> + <description> + All messages to and from this implementation must be logged + </description> + </intent> + +</definitions>
\ No newline at end of file |