Update of /cvsroot/commonjava/commonjava-projects/commonjava-enterprise-services/projects/core/src/main/java/org/commonjava/j2ee/services/rewrite
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10019/projects/core/src/main/java/org/commonjava/j2ee/services/rewrite
Added Files:
RewriteRule.java LocationRewriter.java
Log Message:
modified to make core, ejb, jms, jdbc, raw-service sub-projects, and to add JNDI name rewriting to the core ServiceLocator.
--- NEW FILE: RewriteRule.java ---
/* Created on Mar 22, 2004 */
package org.commonjava.j2ee.services.rewrite;
/** Represents a rule for matching/replacing JNDI lookup names, in order to help provide a mapping
* for logical app-internal JNDI pseudo-bindings to external environment-specific JNDI bindings.
*
* @author John Casey
*
* @opl.parser node="rewriteRule" root="false"
* @opl.aux-import import="java.util.regex.Pattern"
* @opl.child-of
* class="org.commonjava.j2ee.services.rewrite.LocationRewriterParser"
* required="true"
* setter="addRule(@@value)"
*/
public final class RewriteRule {
private String match;
private String replace;
/** Create a new RewriteRule instance.
*/
public RewriteRule() {
}
/** Return the regex used to determine whether this rule applies to the binding in question.
*/
public String getMatch() {
return match;
}
/** Return the replacement pattern when this rule applies to the binding in question.
*/
public String getReplace() {
return replace;
}
/** Set the regex used to determine whether this rule applies to the binding in question.
*
* @opl.attribute
* name="match"
* type="string"
* required="true"
* resolve-value="true"
* before-children="true"
* validator="Pattern.compile(@@value) != null"
*/
public void setMatch(String string) {
match = string;
}
/** Set the replacement pattern when this rule applies to the binding in question.
*
* @opl.attribute
* name="replace"
* type="string"
* required="true"
* resolve-value="true"
* before-children="true"
*/
public void setReplace(String string) {
replace = string;
}
/** Perform match/replace on the specified value, and return the result.
*/
public String rewrite(String value){
return value.replaceAll(match, replace);
}
}
--- NEW FILE: LocationRewriter.java ---
/* Created on Mar 22, 2004 */
package org.commonjava.j2ee.services.rewrite;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.commonjava.config.snapin.ConfigSnapIn;
/** Handles rewriting JNDI bindings from in-app logical bindings (eg. "MyEJB") to
* the actual bindings which are found in JNDI (eg. "MyEJB-1.1"). This is a layer of
* indirection which allows the separation of application logic and requirements from
* environmental considerations, like binding collisions or component versioning.
*
* @author John Casey
*
* @opl.parser node="locationRewriter" root="false"
* @opl.properties-container delegated="false"
* @opl.aux-import import="org.commonjava.config.snapin.SnapInContainer"
* @opl.parent-of ref="rewriteRule" minOccurs="0" maxOccurs="unbounded"
* @opl.child-of
* class="org.commonjava.config.snapin.SnapInContainer"
* required="true"
* setter="addSnapIn(@@value)"
*/
public final class LocationRewriter implements ConfigSnapIn{
public static final String SNAP_IN_ID = LocationRewriter.class.getName();
private List rules = new ArrayList();
/** Create a new location rewriter instance.
*/
public LocationRewriter() {
}
/** Retrieve the snap-in binding ID for this config snap-in.
* @see org.commonjava.config.snapin.ConfigSnapIn#getSnapInId()
*/
public String getSnapInId() {
return SNAP_IN_ID;
}
/** Add a new RewriteRule to this rewriter configuration.
*
* @opl.delegate
*/
public void addRule(RewriteRule rule){
rules.add(rule);
}
/** Perform all match/replace rules on the specified value, and return the result.
*/
public String rewrite(String value){
String result = value;
for (Iterator it = rules.iterator(); it.hasNext();) {
RewriteRule rule = (RewriteRule)it.next();
result = rule.rewrite(result);
}
return result;
}
}
|