Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWITCHYARD-1308 Implement binding.sca and extensions #480

Merged
merged 1 commit into from Feb 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions api/src/main/java/org/switchyard/Context.java
Expand Up @@ -26,6 +26,13 @@
* service consumer and provider.
*/
public interface Context {

/**
* Creates a shallow copy of the existing Context including all properties in all scopes.
* Properties with a label of Labels.TRANSIENT are not included in the copy.
* @return a copy of this context
*/
Context copy();

/**
* Retrieves the named property within this context, regardless
Expand Down Expand Up @@ -74,6 +81,13 @@ public interface Context {
* scope. If there are no properties in the scope, an empty set is returned.
*/
Set<Property> getProperties(Scope scope);

/**
* Get all properties with a given label.
* @param label the label each property must have
* @return set of properties with the specified label
*/
Set<Property> getProperties(String label);

/**
* Removes the named property from this context.
Expand All @@ -92,6 +106,12 @@ public interface Context {
* @param scope scope of the properties to remove
*/
void removeProperties(Scope scope);

/**
* Remove all properties with a given label.
* @param label the label each property must have
*/
void removeProperties(String label);

/**
* Sets the named context property with the specified value. If the context
Expand Down
38 changes: 38 additions & 0 deletions api/src/main/java/org/switchyard/Labels.java
@@ -0,0 +1,38 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @author tags. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.switchyard;

/**
* This class contains constant declarations for well-known context property labels.
*/
public final class Labels {

/**
* Properties labeled as transient are not serialized and are not preserved in
* a copy of the exchange via Context.copy().
*/
public static final String TRANSIENT = "org.switchyard.labels.transient";

/**
* Prevent instantiation of this class
*/
private Labels() {

}
}
9 changes: 5 additions & 4 deletions api/src/main/java/org/switchyard/Property.java
@@ -1,6 +1,3 @@
package org.switchyard;

import java.util.Set;
/*
* JBoss, Home of Professional Open Source
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
Expand All @@ -20,11 +17,15 @@
* MA 02110-1301, USA.
*/

package org.switchyard;

import java.util.Set;

/**
* Represents a context property consisting of a name, scope, and value.
*/
public interface Property {

/**
* The scope of the property.
* @return property scope
Expand Down
5 changes: 3 additions & 2 deletions api/src/main/java/org/switchyard/policy/PolicyUtil.java
Expand Up @@ -23,6 +23,7 @@
import java.util.Set;

import org.switchyard.Exchange;
import org.switchyard.Labels;
import org.switchyard.Property;

/**
Expand All @@ -48,7 +49,7 @@ private PolicyUtil() {
public static void provide(Exchange exchange, Policy policy) {
Set<Policy> provided = getPolicies(exchange, PROVIDED_PROPERTY);
provided.add(policy);
exchange.getContext().setProperty(PROVIDED_PROPERTY, provided);
exchange.getContext().setProperty(PROVIDED_PROPERTY, provided).addLabels(Labels.TRANSIENT);
}

/**
Expand Down Expand Up @@ -78,7 +79,7 @@ public static boolean isProvided(Exchange exchange, Policy policy) {
public static void require(Exchange exchange, Policy policy) {
Set<Policy> required = getPolicies(exchange, REQUIRED_PROPERTY);
required.add(policy);
exchange.getContext().setProperty(REQUIRED_PROPERTY, required);
exchange.getContext().setProperty(REQUIRED_PROPERTY, required).addLabels(Labels.TRANSIENT);
}

/**
Expand Down
Expand Up @@ -27,6 +27,7 @@

import org.apache.log4j.Logger;
import org.switchyard.Exchange;
import org.switchyard.Labels;
import org.switchyard.Message;
import org.switchyard.Property;
import org.switchyard.Scope;
Expand Down Expand Up @@ -71,7 +72,7 @@ private TransformSequence() {
*/
public void associateWith(Exchange exchange, Scope scope) {
exchange.getContext().setProperty(
TransformSequence.class.getName(), this, scope);
TransformSequence.class.getName(), this, scope).addLabels(Labels.TRANSIENT);
}

/**
Expand Down
35 changes: 35 additions & 0 deletions api/src/test/java/org/switchyard/MockContext.java
Expand Up @@ -36,6 +36,14 @@ public class MockContext implements Context {
private final Map<String,Property> _outProperties = Collections.synchronizedMap(new HashMap<String,Property>());

public MockContext() {}

private MockContext(Map<String, Property> exchangeProps,
Map<String, Property> inProps,
Map<String, Property> outProps) {
_exchangeProperties.putAll(exchangeProps);
_inProperties.putAll(inProps);
_outProperties.putAll(outProps);
}

private Map<String,Property> getPropertiesMap(Scope scope) {
switch (scope) {
Expand Down Expand Up @@ -153,4 +161,31 @@ public Context setProperties(Set<Property> properties) {
return this;
}

@Override
public Context copy() {
MockContext ctx = new MockContext(_exchangeProperties, _inProperties, _outProperties);
ctx.removeProperties(Labels.TRANSIENT);
return ctx;
}

@Override
public Set<Property> getProperties(String label) {
Set<Property> props = new HashSet<Property>();
for (Property p : getProperties()) {
if (p.hasLabel(label)) {
props.add(p);
}
}
return props;
}

@Override
public void removeProperties(String label) {
for (Property p : getProperties()) {
if (p.hasLabel(label)) {
removeProperty(p);
}
}
}

}
@@ -0,0 +1,123 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @author tags. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/

package org.switchyard.config.model.composite;

import javax.xml.namespace.QName;

import org.switchyard.config.model.switchyard.SwitchYardModel;

/**
* SCABindingModel represents the standard binding.sca binding in SCA. SwitchYard supports a
* set of extensions which are represented as attributes on the binding.sca element which are exposed
* via this config model.
*/
public interface SCABindingModel extends BindingModel {

/** The "sca" name. */
public static final String SCA = "sca";

/** The "target" name. */
public static final QName TARGET = new QName(SwitchYardModel.DEFAULT_NAMESPACE, "target");

/** The "target" name. */
public static final QName TARGET_NAMESPACE = new QName(SwitchYardModel.DEFAULT_NAMESPACE, "targetNamespace");

/** The "loadBalance" name. */
public static final QName LOAD_BALANCE = new QName(SwitchYardModel.DEFAULT_NAMESPACE, "loadBalance");

/** The "clustered" name. */
public static final QName CLUSTERED = new QName(SwitchYardModel.DEFAULT_NAMESPACE, "clustered");

/**
* Indicates whether clustering is enabled.
* @return true if clustering is enabled, false otherwise
*/
boolean isClustered();

/**
* Specifies whether clustering is enabled for the service binding. Valid for service and
* reference bindings.
* @param clustered true for enabled, false for disabled
* @return this config model instance
*/
SCABindingModel setClustered(boolean clustered);

/**
* Indicates whether load balancing is enabled.
* @return true if load balancing is enabled, false otherwise
*/
boolean isLoadBalanced();

/**
* Returns the load balance strategy used by the binding.
* @return the load balance strategy in use
*/
String getLoadBalance();

/**
* Specifies the strategy used for load balancing. This attribute is only valid for reference
* bindings.
* @param loadBalance the load balance strategy used
* @return this config model instance
*/
SCABindingModel setLoadBalance(String loadBalance);

/**
* Indicates whether a target service has been specified for the binding.
* @return true if a target service is specified, false otherwise
*/
boolean hasTarget();

/**
* Returns the target service name used for the binding.
* @return target service name
*/
String getTarget();

/**
* Specifies the target service name used for this binding. This is valid for reference
* bindings only and allows the service name to be overloaded in case the provider service
* has a different name.
* @param target target service name
* @return this config model instance
*/
SCABindingModel setTarget(String target);

/**
* Indicates whether a target namespace has been specified for the binding.
* @return true if a target namespace is specified, false otherwise
*/
boolean hasTargetNamespace();

/**
* Returns the target namespace used for the binding.
* @return target namespace
*/
String getTargetNamespace();

/**
* Specifies the target namespace used for this binding. This is valid for reference
* bindings only and allows the service namespace to be overloaded in case the provider service
* has a different namespace.
* @param namespace target service namespace
* @return this config model instance
*/
SCABindingModel setTargetNamespace(String namespace);
}
Expand Up @@ -30,6 +30,7 @@
import org.switchyard.config.model.composite.CompositeModel;
import org.switchyard.config.model.composite.CompositeServiceModel;
import org.switchyard.config.model.composite.InterfaceModel;
import org.switchyard.config.model.composite.SCABindingModel;
import org.switchyard.config.model.property.PropertyModel;
import org.switchyard.config.model.property.v1.V1PropertyModel;

Expand Down Expand Up @@ -67,7 +68,11 @@ public Model read(Configuration config) {
}
}
} else if (name.startsWith(BindingModel.BINDING)) {
return new V1BindingModel(config, desc);
if (name.endsWith("." + SCABindingModel.SCA)) {
return new V1SCABindingModel(config, desc);
} else {
return new V1BindingModel(config, desc);
}
} else if (name.equals(ComponentModel.COMPONENT)) {
return new V1ComponentModel(config, desc);
} else if (name.startsWith(ComponentImplementationModel.IMPLEMENTATION)) {
Expand All @@ -92,6 +97,7 @@ public Model read(Configuration config) {
} else if (name.equals(PropertyModel.PROPERTY)) {
return new V1PropertyModel(config,desc);
}

return null;
}

Expand Down