01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.rewriter.rom.js;
06:
07: import com.sun.portal.rewriter.rom.Data;
08: import com.sun.portal.rewriter.util.Debug;
09: import com.sun.portal.rewriter.util.StringHelper;
10: import com.sun.portal.rewriter.util.xml.Node;
11:
12: /**
13: * Represents Variable tag of JSRules
14: *
15: * @version 1.0 12/15/2001
16: * @author Raja Nagendra Kumar, Nagendra.Raja@sun.com
17: */
18: public final class VariableRule extends JSDataRule {
19: public static final int ANY = 0;
20: private final Variable variable;
21:
22: public VariableRule(final Variable aVariable) {
23: super (aVariable);
24: variable = aVariable;
25: }//constructor
26:
27: public VariableRule(final Node aNode) {
28: this (createVariable(aNode));
29: }//constructor
30:
31: private static Variable createVariable(final Node aNode) {
32: //Start:Read Variable Name - Compatability Code
33: String varName = aNode.getAttributeValue(NAME);
34: if (StringHelper.normalize(varName).length() == 0) {
35: varName = aNode.getPCData();
36: }
37: //End:Read Variable Name - Compatability Code
38:
39: return new Variable(varName, aNode.getAttributeValue(TYPE),
40: aNode.getAttributeValue(SOURCE));
41: }//createVariable()
42:
43: public Variable getVariable() {
44: return variable;
45: }//getVariable()
46:
47: public boolean plugableMatch(final Data aMache) {
48: if (!(aMache instanceof Variable)) {
49: return false;
50: }
51:
52: Variable valueObject = (Variable) aMache;
53: if (valueObject.getTypeCode() == ANY) {
54: return matchCommon(valueObject);
55: } else {
56: if (variable.getTypeCode() == valueObject.getTypeCode()) {
57: return matchCommon(valueObject);
58: }
59: }
60:
61: return false;
62: }//matchs()
63:
64: public boolean isValid() {
65: return doBasicValidation(new String[] { variable.getName() });
66: }//isValid()
67:
68: public static void main(String[] args) {
69: VariableRule[] variables = com.sun.portal.rewriter.test.util.SampleRuleObjects.defaultJSVariables;
70: for (int i = 0; i < variables.length; i++) {
71: Debug.println(variables[i].toXML());
72: }//for loop
73: }//main()
74:
75: }//class Variable
|