You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2006/03/20 17:31:33 UTC
svn commit: r387239 [12/21] - in
/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math: ./
Harmony/ doc/ doc/images/ make/ src/ src/common/ src/common/javasrc/
src/common/javasrc/java/ src/common/javasrc/java/applet/
src/common/javasrc/ja...
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/ReluctantCompositeQuantifierSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/ReluctantCompositeQuantifierSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/ReluctantCompositeQuantifierSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/ReluctantCompositeQuantifierSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Reluctant version of composite(i.e. {n,m}) quantifier set over leaf nodes.
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+class ReluctantCompositeQuantifierSet extends CompositeQuantifierSet {
+
+ public ReluctantCompositeQuantifierSet(Quantifier quant, LeafSet innerSet,
+ AbstractSet next, int type) {
+ super(quant, innerSet, next, type);
+ }
+
+ public int matches(int stringIndex, CharSequence testString,
+ MatchResultImpl matchResult) {
+ int min = quantifier.min();
+ int max = quantifier.max();
+ int i = 0;
+ int shift = 0;
+
+ for (; i < min; i++) {
+
+ if (stringIndex + leaf.charCount() > matchResult.getRightBound()) {
+ matchResult.hitEnd = true;
+ return -1;
+ }
+
+ shift = leaf.accepts(stringIndex, testString);
+ if (shift < 1) {
+ return -1;
+ }
+ stringIndex += shift;
+ }
+
+ do {
+ shift = next.matches(stringIndex, testString, matchResult);
+ if (shift >= 0) {
+ return shift;
+ }
+
+ if (stringIndex + leaf.charCount() <= matchResult.getRightBound()) {
+ shift = leaf.accepts(stringIndex, testString);
+ stringIndex += shift;
+ i++;
+ }
+
+ } while (shift >= 1 && i < max);
+
+ return -1;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/ReluctantGroupQuantifierSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/ReluctantGroupQuantifierSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/ReluctantGroupQuantifierSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/ReluctantGroupQuantifierSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.9.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Relactant version of the group quantifier set.
+ *
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.9.2.2 $
+ */
+class ReluctantGroupQuantifierSet extends GroupQuantifierSet {
+
+ public ReluctantGroupQuantifierSet(AbstractSet innerSet, AbstractSet next,
+ int type) {
+ super(innerSet, next, type);
+ }
+
+ public int matches(int stringIndex, CharSequence testString,
+ MatchResultImpl matchResult) {
+
+ if (!innerSet.hasConsumed(matchResult))
+ return next.matches(stringIndex, testString, matchResult);
+
+ int res = next.matches(stringIndex, testString, matchResult);
+ if (res < 0) {
+ return innerSet.matches(stringIndex, testString, matchResult);
+ } else {
+ return res;
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/ReluctantQuantifierSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/ReluctantQuantifierSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/ReluctantQuantifierSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/ReluctantQuantifierSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * This class represents [+*]? constructs over LeafSets.
+ *
+ * @see java.util.regex.LeafSet
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+class ReluctantQuantifierSet extends LeafQuantifierSet {
+
+ public ReluctantQuantifierSet(LeafSet innerSet, AbstractSet next, int type) {
+ super(innerSet, next, type);
+ }
+
+ public int matches(int stringIndex, CharSequence testString,
+ MatchResultImpl matchResult) {
+ int i = 0;
+ int shift = 0;
+
+ do {
+ shift = next.matches(stringIndex, testString, matchResult);
+ if (shift >= 0) {
+ return shift;
+ }
+
+ if (stringIndex + leaf.charCount() <= matchResult.getRightBound()) {
+ shift = leaf.accepts(stringIndex, testString);
+ stringIndex += shift;
+ }
+ } while (shift >= 1);
+
+ return -1;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SOLSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SOLSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SOLSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SOLSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.7.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Represents node accepting single character.
+ *
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.7.2.2 $
+ */
+final class SOLSet extends AbstractSet {
+
+ public int matches(int strIndex, CharSequence testString,
+ MatchResultImpl matchResult) {
+ if (strIndex == 0
+ || (matchResult.hasAnchoringBounds() && strIndex == matchResult
+ .getLeftBound())) {
+ return next.matches(strIndex, testString, matchResult);
+ }
+ return -1;
+ }
+
+ public boolean hasConsumed(MatchResultImpl matchResult) {
+ return false;
+ }
+
+ protected String getName() {
+ return "<SOL>";
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SequenceSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SequenceSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SequenceSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SequenceSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,216 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.15.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * This class represents nodes constructed with character sequenses. For
+ * example, lets consider regular expression: ".*word.*". During regular
+ * expression compilation phase character sequense w-o-r-d, will be represented
+ * with single node for the entire word.
+ *
+ * During the match phase, Moyer-Moore algorithm will be used for fast
+ * searching.
+ *
+ * Please follow the next link for more details about mentioned algorithm:
+ * http://portal.acm.org/citation.cfm?id=359859
+ *
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.15.2.2 $
+ */
+class SequenceSet extends LeafSet {
+
+ private String string = null;
+
+ private IntHash leftToRight;
+
+ private IntHash rightToLeft;
+
+ SequenceSet(StringBuffer substring) {
+ this.string = substring.toString();
+ charCount = substring.length();
+
+ leftToRight = new IntHash(charCount);
+ rightToLeft = new IntHash(charCount);
+ for (int j = 0; j < charCount - 1; j++) {
+ leftToRight.put(string.charAt(j), charCount - j - 1);
+ rightToLeft
+ .put(string.charAt(charCount - j - 1), charCount - j - 1);
+ }
+ }
+
+ public int accepts(int strIndex, CharSequence testString) {
+ return startsWith(testString, strIndex) ? charCount : -1;
+ }
+
+ public int find(int strIndex, CharSequence testString,
+ MatchResultImpl matchResult) {
+ String testStr = testString.toString();
+ int strLength = matchResult.getRightBound();
+
+ while (strIndex <= strLength) {
+ strIndex = indexOf(testStr, strIndex);
+
+ if (strIndex < 0)
+ return -1;
+ if (next.matches(strIndex + charCount, testString, matchResult) >= 0)
+ return strIndex;
+
+ strIndex++;
+ }
+
+ return -1;
+ }
+
+ public int findBack(int strIndex, int lastIndex, CharSequence testString,
+ MatchResultImpl matchResult) {
+ String testStr = testString.toString();
+
+ while (lastIndex >= strIndex) {
+ lastIndex = lastIndexOf(testString, strIndex, lastIndex);
+
+ if (lastIndex < 0)
+ return -1;
+ if (next.matches(lastIndex + charCount, testString, matchResult) >= 0)
+ return lastIndex;
+
+ lastIndex--;
+ }
+
+ return -1;
+ }
+
+ public String getName() {
+ return "secuence: " + string;
+ }
+
+ public boolean first(AbstractSet set) {
+ if (set instanceof CharSet) {
+ return ((CharSet) set).getChar() == string.charAt(0);
+ } else if (set instanceof RangeSet) {
+ return ((RangeSet) set).accepts(0, string.substring(0, 1)) > 0;
+ }
+
+ return true;
+ }
+
+ protected int indexOf(CharSequence str, int from) {
+ int last = string.charAt(charCount - 1);
+ int i = from;
+ int size = str.length();
+
+ while (i <= size - charCount) {
+ char ch = str.charAt(i + charCount - 1);
+ if (ch == last && startsWith(str, i)) {
+ return i;
+ }
+
+ i += leftToRight.get(ch);
+ }
+ return -1;
+ }
+
+ protected int lastIndexOf(CharSequence str, int to, int from) {
+ int first = string.charAt(0);
+ int size = str.length();
+ int delta;
+ int i = ((delta = size - from - charCount) > 0) ? from : from + delta;
+
+ while (i >= to) {
+ char ch = str.charAt(i);
+ if (ch == first && startsWith(str, i)) {
+ return i;
+ }
+
+ i -= rightToLeft.get(ch);
+ }
+ return -1;
+ }
+
+ protected boolean startsWith(CharSequence str, int from) {
+ for (int i = 0; i < charCount; i++) {
+ if (str.charAt(i + from) != string.charAt(i))
+ return false;
+ }
+ return true;
+ }
+
+ class IntHash {
+ int[] table, values;
+
+ int mask;
+
+ int size; // <-maximum shift
+
+ public IntHash(int size) {
+ while (size >= mask) {
+ mask = (mask << 1) | 1;
+ }
+ mask = (mask << 1) | 1;
+ table = new int[mask + 1];
+ values = new int[mask + 1];
+ this.size = size;
+ }
+
+ public void put(int key, int value) {
+ int i = 0;
+ int hashCode = key & mask;
+
+ for (;;) {
+ if (table[hashCode] == 0 // empty
+ || table[hashCode] == key) {// rewrite
+ table[hashCode] = key;
+ values[hashCode] = value;
+ return;
+ }
+ i++;
+ i &= mask;
+
+ hashCode += i;
+ hashCode &= mask;
+ }
+ }
+
+ public int get(int key) {
+
+ int hashCode = key & mask;
+ int i = 0;
+ int storedKey;
+
+ for (;;) {
+ storedKey = table[hashCode];
+
+ if (storedKey == 0) { // empty
+ return size;
+ }
+
+ if (storedKey == key) {
+ return values[hashCode];
+ }
+
+ i++;
+ i &= mask;
+
+ hashCode += i;
+ hashCode &= mask;
+ }
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SingleSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SingleSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SingleSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SingleSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Group node over subexpression w/o alternations.
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+class SingleSet extends JointSet {
+
+ private AbstractSet kid;
+
+ public SingleSet(AbstractSet child, FSet fSet) {
+ this.kid = child;
+ this.fSet = fSet;
+ this.groupIndex = fSet.getGroupIndex();
+ }
+
+ public int matches(int stringIndex, CharSequence testString,
+ MatchResultImpl matchResult) {
+ int start = matchResult.getStart(groupIndex);
+ matchResult.setStart(groupIndex, stringIndex);
+ int shift = kid.matches(stringIndex, testString, matchResult);
+ if (shift >= 0) {
+ return shift;
+ }
+ matchResult.setStart(groupIndex, start);
+ return -1;
+ }
+
+ public int find(int stringIndex, CharSequence testString,
+ MatchResultImpl matchResult) {
+ int res = kid.find(stringIndex, testString, matchResult);
+ if (res >= 0)
+ matchResult.setStart(groupIndex, res);
+ return res;
+ }
+
+ public int findBack(int stringIndex, int lastIndex,
+ CharSequence testString, MatchResultImpl matchResult) {
+ int res = kid.findBack(stringIndex, lastIndex, testString, matchResult);
+ if (res >= 0)
+ matchResult.setStart(groupIndex, res);
+ return res;
+ }
+
+ public boolean first(AbstractSet set) {
+ return kid.first(set);
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SpecialToken.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SpecialToken.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SpecialToken.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/SpecialToken.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.6.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * This is base class for special tokens like character classes
+ * and quantifiers.
+ *
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.6.2.2 $
+ */
+abstract class SpecialToken {
+
+ public static final int TOK_CHARCLASS = 1 << 0;
+
+ public static final int TOK_QUANTIFIER = 1 << 1;
+
+ /**
+ * Returns the type of the token, may return following values:
+ * TOK_CHARCLASS - token representing character class;
+ * TOK_QUANTIFIER - token representing quantifier;
+ *
+ * @return character type.
+ */
+ public abstract int getType();
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCIBackReferenceSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCIBackReferenceSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCIBackReferenceSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCIBackReferenceSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.7.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Unicode case insensitive back reference (i.e. \1-9) node.
+ *
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.7.2.2 $
+ */
+class UCIBackReferenceSet extends CIBackReferenceSet {
+
+ int groupIndex;
+
+ public UCIBackReferenceSet(int groupIndex, int consCounter) {
+ super(groupIndex, consCounter);
+ }
+
+ public int matches(int stringIndex, CharSequence testString,
+ MatchResultImpl matchResult) {
+ String group = getString(matchResult);
+
+ if (group == null
+ || (stringIndex + group.length()) > matchResult.getRightBound())
+ return -1;
+
+ for (int i = 0; i < group.length(); i++) {
+ if (Character.toLowerCase(Character.toUpperCase(group.charAt(i))) != Character
+ .toLowerCase(Character.toUpperCase(testString
+ .charAt(stringIndex + i)))) {
+ return -1;
+ }
+ }
+ matchResult.setConsumed(consCounter, group.length());
+ return next.matches(stringIndex + group.length(), testString,
+ matchResult);
+ }
+
+ public String getName() {
+ return "UCI back reference: " + this.groupIndex;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCICharSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCICharSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCICharSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCICharSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.7.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Represents node accepting single character in unicode case
+ * insensitive manner.
+ *
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.7.2.2 $
+ */
+class UCICharSet extends LeafSet {
+
+ private char ch;
+
+ public UCICharSet(char ch) {
+ this.ch = Character.toLowerCase(Character.toUpperCase(ch));
+ }
+
+ public int accepts(int strIndex, CharSequence testString) {
+ return (this.ch == Character.toLowerCase(Character
+ .toUpperCase(testString.charAt(strIndex)))) ? 1 : -1;
+ }
+
+ protected String getName() {
+ return "UCI " + ch;
+ }
+
+ protected char getChar() {
+ return ch;
+ }
+}
\ No newline at end of file
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCIRangeSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCIRangeSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCIRangeSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCIRangeSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.7.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Represents node accepting single character from the given char class. Note,
+ * this class contains normalaized characters fo unicode case, asci case is
+ * supported through adding both symbols to the range.
+ *
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.7.2.2 $
+ */
+class UCIRangeSet extends LeafSet {
+
+ private AbstractCharClass chars;
+
+ private boolean alt = false;
+
+ public UCIRangeSet(AbstractCharClass cs, AbstractSet next) {
+ super(next);
+ this.chars = cs.getInstance();
+ this.alt = cs.alt;
+ }
+
+ public int accepts(int strIndex, CharSequence testString) {
+ return (chars.contains(Character.toLowerCase(Character
+ .toUpperCase(testString.charAt(strIndex))))) ? 1 : -1;
+ }
+
+ protected String getName() {
+ return "UCI range:" + (alt ? "^ " : " ") + chars.toString();
+ }
+}
\ No newline at end of file
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCISequenceSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCISequenceSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCISequenceSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UCISequenceSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.7.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Node accepting substrings in unicode case insensitive manner.
+ *
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.7.2.2 $
+ */
+class UCISequenceSet extends LeafSet {
+
+ private String string = null;
+
+ UCISequenceSet(StringBuffer substring) {
+ StringBuffer res = new StringBuffer();
+ for (int i = 0; i < substring.length(); i++) {
+ res.append(Character.toLowerCase(Character.toUpperCase(substring
+ .charAt(i))));
+ }
+ this.string = res.toString();
+ this.charCount = res.length();
+ }
+
+ public int accepts(int strIndex, CharSequence testString) {
+ for (int i = 0; i < string.length(); i++) {
+ if (string.charAt(i) != Character.toLowerCase(Character
+ .toUpperCase(testString.charAt(strIndex + i)))) {
+ return -1;
+ }
+ }
+
+ return string.length();
+
+ }
+
+ public String getName() {
+ return "UCI secuence: " + string;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UEOLSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UEOLSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UEOLSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UEOLSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.3.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Unix line terminator, accepting only \n.
+ *
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.3.2.2 $
+ */
+final class UEOLSet extends AbstractSet {
+
+ private int consCounter;
+
+ public UEOLSet(int counter) {
+ this.consCounter = counter;
+ }
+
+ public int matches(int strIndex, CharSequence testString,
+ MatchResultImpl matchResult) {
+ int rightBound = matchResult.hasAnchoringBounds() ? matchResult
+ .getRightBound() : testString.length();
+
+ if (strIndex >= rightBound) {
+ matchResult.setConsumed(consCounter, 0);
+ return next.matches(strIndex, testString, matchResult);
+ }
+ // check final line terminator;
+
+ if ((rightBound - strIndex) == 1 && testString.charAt(strIndex) == '\n') {
+ matchResult.setConsumed(consCounter, 1);
+ return next.matches(strIndex + 1, testString, matchResult);
+ }
+
+ return -1;
+ }
+
+ public boolean hasConsumed(MatchResultImpl matchResult) {
+ int cons;
+ boolean res = ((cons = matchResult.getConsumed(consCounter)) < 0 || cons > 0);
+ matchResult.setConsumed(consCounter, -1);
+ return res;
+ }
+
+ protected String getName() {
+ return "<EOL>";
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UMultiLineEOLSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UMultiLineEOLSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UMultiLineEOLSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UMultiLineEOLSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.4.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Unix style multiline end-of-line node.
+ *
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.4.2.2 $
+ */
+class UMultiLineEOLSet extends AbstractSet {
+
+ private int consCounter;
+
+ public UMultiLineEOLSet(int counter) {
+ this.consCounter = counter;
+ }
+
+ public int matches(int strIndex, CharSequence testString,
+ MatchResultImpl matchResult) {
+ int strDif = matchResult.hasAnchoringBounds() ? matchResult
+ .getLeftBound()
+ - strIndex : testString.length() - strIndex;
+ if (strDif <= 0) {
+ matchResult.setConsumed(consCounter, 0);
+ return next.matches(strIndex, testString, matchResult);
+ } else if (testString.charAt(strIndex) == '\n') {
+ matchResult.setConsumed(consCounter, 1);
+ return next.matches(strIndex + 1, testString, matchResult);
+ }
+ return -1;
+ }
+
+ public boolean hasConsumed(MatchResultImpl matchResult) {
+ int cons;
+ boolean res = ((cons = matchResult.getConsumed(consCounter)) < 0 || cons > 0);
+ matchResult.setConsumed(consCounter, -1);
+ return res;
+ }
+
+ protected String getName() {
+ return "<Unix MultiLine $>";
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UnicodeCategory.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UnicodeCategory.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UnicodeCategory.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UnicodeCategory.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.5.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Unicode category (i.e. Ll, Lu).
+ *
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.5.2.2 $
+ */
+class UnicodeCategory extends AbstractCharClass {
+
+ protected int category;
+
+ public UnicodeCategory(int category) {
+ this.category = category;
+ }
+
+ public boolean contains(int ch) {
+ return alt ^ (category == Character.getType((char) ch));
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UnicodeCategoryScope.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UnicodeCategoryScope.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UnicodeCategoryScope.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UnicodeCategoryScope.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.5.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Unicode category scope (i.e IsL, IsM, ...)
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.5.2.2 $
+ */
+class UnicodeCategoryScope extends UnicodeCategory {
+
+ public UnicodeCategoryScope(int category) {
+ super(category);
+ }
+
+ public boolean contains(int ch) {
+ return alt ^ ((category >> Character.getType((char) ch)) & 1) != 0;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UnifiedQuantifierSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UnifiedQuantifierSet.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UnifiedQuantifierSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/UnifiedQuantifierSet.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Greedy quantifier node for the case where there is no intersection with
+ * next node and normal quantifiers could be treated as greedy and possessive.
+ *
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.8.2.2 $
+ */
+class UnifiedQuantifierSet extends LeafQuantifierSet {
+
+ public UnifiedQuantifierSet(LeafSet innerSet, AbstractSet next, int type) {
+ super(innerSet, next, type);
+ }
+
+ public UnifiedQuantifierSet(LeafQuantifierSet quant) {
+ super((LeafSet) quant.getInnerSet(), quant.getNext(), quant.getType());
+ innerSet.setNext(this);
+
+ }
+
+ public int matches(int stringIndex, CharSequence testString,
+ MatchResultImpl matchResult) {
+ while (stringIndex + leaf.charCount() <= matchResult.getRightBound()
+ && leaf.accepts(stringIndex, testString) > 0)
+ stringIndex++;
+
+ return next.matches(stringIndex, testString, matchResult);
+ }
+
+ public int find(int stringIndex, CharSequence testString,
+ MatchResultImpl matchResult) {
+ int startSearch = next.find(stringIndex, testString, matchResult);
+ if (startSearch < 0)
+ return -1;
+ int newSearch = startSearch - 1;
+ while (newSearch >= stringIndex
+ && leaf.accepts(newSearch, testString) > 0) {
+ startSearch = newSearch;
+ newSearch--;
+ }
+
+ return startSearch;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/WordBoundary.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/WordBoundary.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/WordBoundary.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/util/regex/WordBoundary.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.3.2.2 $
+ */
+package java.util.regex;
+
+/**
+ * Represents word boundary, checks current character and previous one if
+ * differet types returns true;
+ *
+ * @author Nikolay A. Kuznetsov
+ * @version $Revision: 1.3.2.2 $
+ */
+class WordBoundary extends AbstractSet {
+
+ boolean positive;
+
+ public WordBoundary(boolean positive) {
+ this.positive = positive;
+ }
+
+ public int matches(int stringIndex, CharSequence testString,
+ MatchResultImpl matchResult) {
+ boolean left;
+ boolean right;
+
+ char ch1 = stringIndex >= testString.length() ? ' ' : testString
+ .charAt(stringIndex);
+ char ch2 = stringIndex == 0 ? ' ' : testString.charAt(stringIndex - 1);
+
+ int leftBound = matchResult.hasTransparentBounds() ? 0 : matchResult
+ .getLeftBound();
+ left = (ch1 == ' ') || isSpace(ch1, stringIndex, leftBound, testString);
+ right = (ch2 == ' ')
+ || isSpace(ch2, stringIndex - 1, leftBound, testString);
+ return ((left ^ right) ^ positive) ? -1 : next.matches(stringIndex,
+ testString, matchResult);
+ }
+
+ /**
+ * Returns false, because word boundary does not consumes any characters and
+ * do not move string index.
+ */
+ public boolean hasConsumed(MatchResultImpl matchResult) {
+ // only checks boundary, do not consumes characters
+ return false;
+ }
+
+ protected String getName() {
+ return "WordBoundary";
+ }
+
+ private boolean isSpace(char ch, int index, int leftBound,
+ CharSequence testString) {
+ if (Character.isLetterOrDigit(ch) || ch == '_')
+ return false;
+ if (Character.getType(ch) == Character.NON_SPACING_MARK) {
+ for (; --index >= leftBound;) {
+ ch = testString.charAt(index);
+ if (Character.isLetterOrDigit(ch))
+ return false;
+ if (Character.getType(ch) != Character.NON_SPACING_MARK)
+ return true;
+ }
+ }
+ return true;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/org/apache/harmony/beans/Argument.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/org/apache/harmony/beans/Argument.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/org/apache/harmony/beans/Argument.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/org/apache/harmony/beans/Argument.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.1.2.1 $
+ */
+package org.apache.harmony.beans;
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.1.2.1 $
+ */
+
+public class Argument {
+
+ private Class type = null;
+ private Object value = null;
+ private Class[] interfaces = null;
+
+ public Argument(Object value) {
+ this.value = value;
+ if(this.value != null) {
+ this.type = value.getClass();
+ this.interfaces = this.type.getInterfaces();
+ }
+ }
+
+ public Argument(Class type, Object value) {
+ this.type = type;
+ this.value = value;
+ this.interfaces = type.getInterfaces();
+ }
+
+ public Class getType() { return type; }
+
+ public Object getValue() { return value; }
+
+ public Class[] getInterfaces() { return interfaces; }
+
+ public void setType(Class type) {
+ this.type = type;
+ this.interfaces = type.getInterfaces();
+ }
+
+ public void setInterfaces(Class[] interfaces) {
+ this.interfaces = interfaces;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/org/apache/harmony/beans/ArrayPersistenceDelegate.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/org/apache/harmony/beans/ArrayPersistenceDelegate.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/org/apache/harmony/beans/ArrayPersistenceDelegate.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/org/apache/harmony/beans/ArrayPersistenceDelegate.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.1.2.1 $
+ */
+package org.apache.harmony.beans;
+
+import java.beans.Encoder;
+import java.beans.Expression;
+import java.beans.PersistenceDelegate;
+import java.beans.Statement;
+import java.lang.reflect.Array;
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.1.2.1 $
+ */
+
+public class ArrayPersistenceDelegate extends PersistenceDelegate {
+
+ private static PersistenceDelegate pd = null;
+
+ public static PersistenceDelegate getInstance() {
+ if(pd == null) {
+ pd = new ArrayPersistenceDelegate();
+ }
+ return pd;
+ }
+
+ protected Expression instantiate(Object oldInstance, Encoder out) {
+ Class type = getArrayWrapperClass(oldInstance.getClass());
+ int length = Array.getLength(oldInstance);
+ return new Expression(oldInstance, type, "new",
+ new Object[] { new Integer(length) });
+ }
+
+ protected void initialize(
+ Class type, Object oldInstance, Object newInstance, Encoder out) {
+ int length = Array.getLength(oldInstance);
+ Class componentType = type.getComponentType();
+
+ Object nullValue = null;
+ if(componentType != null) { // is array
+ Object array = Array.newInstance(componentType, 1);
+ nullValue = Array.get(array, 0);
+ }
+
+ for(int i = 0; i < length; ++i) {
+
+ Object oldValue = Array.get(oldInstance, i);
+ Object newValue = Array.get(newInstance, i);
+
+ if(oldValue != null && !oldValue.equals(newValue) ||
+ oldValue == null && newValue != null)
+ {
+ if(nullValue == null || !nullValue.equals(oldValue)) {
+ Statement s = new Statement(oldInstance, "set",
+ new Object[]{ new Integer(i), oldValue });
+ out.writeStatement(s);
+ }
+ }
+
+ }
+ }
+
+ private static Class getArrayWrapperClass(Class type) {
+ Class result = type;
+ if(type == boolean[].class) {
+ result = Boolean[].class;
+ } else if(type == byte[].class) {
+ result = Byte[].class;
+ } else if(type == char[].class) {
+ result = Character[].class;
+ } else if(type == double[].class) {
+ result = Double[].class;
+ } else if(type == float[].class) {
+ result = Float[].class;
+ } else if(type == int[].class) {
+ result = Integer[].class;
+ } else if(type == long[].class) {
+ result = Long[].class;
+ } else if(type == short[].class) {
+ result = Short[].class;
+ }
+ return result;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/org/apache/harmony/beans/Command.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/org/apache/harmony/beans/Command.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/org/apache/harmony/beans/Command.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/org/apache/harmony/beans/Command.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,819 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.1.2.1 $
+ */
+package org.apache.harmony.beans;
+
+import java.beans.BeanInfo;
+import java.beans.IndexedPropertyDescriptor;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.beans.Statement;
+import java.beans.XMLDecoder;
+import java.beans.Expression;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.xml.sax.Attributes;
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.1.2.1 $
+ */
+
+public class Command {
+
+ private static int INITIALIZED = 0;
+ private static int CHILDREN_FILTERED = 1;
+ private static int COMMAND_EXECUTED = 2;
+ private static int CHILDREN_PROCESSED = 3;
+
+ private String tagName; // tag name
+ private HashMap attrs; // set of attrs
+ private String data = null; // string data
+ private Vector commands = new Vector(); // inner commands
+ private Vector arguments = new Vector(); // arguments
+ private Vector operations = new Vector(); // operations
+ private Vector auxArguments = new Vector(); // additonal arguments placed before others
+ private Argument result = null; // result argument
+ private Object target = null; // target to execute a command on
+ private String methodName = null; // method name
+ private Command ctx = null; // context for command
+ private int status; // commands
+ private int tabCount = 0;
+ private XMLDecoder decoder;
+
+ public Command(String tagName, HashMap attrs) {
+ this.tagName = tagName;
+ this.attrs = attrs;
+ this.status = initializeStatus(tagName);
+ }
+
+ public Command(XMLDecoder decoder, String tagName, HashMap attrs) {
+ this.decoder = decoder;
+ this.tagName = tagName;
+ this.attrs = attrs;
+ this.status = initializeStatus(tagName);
+ }
+
+ // set data for command
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ // set tab count to display log messages
+ public void setTabCount(int tabCount) {
+ this.tabCount = tabCount;
+ }
+
+ // set context - upper level command
+ public void setContext(Command ctx) {
+ this.ctx = ctx;
+ }
+
+ // add child command
+ public void addChild(Command cmd) {
+ if(cmd != null) {
+ cmd.setContext(this);
+ commands.add(cmd);
+ }
+ }
+
+ // remove child command
+ public void removeChild(Command cmd) {
+ if((cmd != null) && commands.remove(cmd))
+ cmd.setContext(null);
+ }
+
+ // command status
+ public int getStatus() {
+ return status;
+ }
+
+ // check if one of arguments or operations is unresolved
+ private boolean isResolved() {
+ if(getStatus() < Command.CHILDREN_PROCESSED) {
+ return false;
+ } else {
+ for(int i = 0; i < arguments.size(); ++i) {
+ Command arg = (Command) arguments.elementAt(i);
+ if(!arg.isResolved()) return false;
+ }
+ for(int j = 0; j < operations.size(); ++j) {
+ Command opr = (Command) operations.elementAt(j);
+ if(!opr.isResolved()) return false;
+ }
+ return true;
+ }
+ }
+
+ // execute command and return execution flags
+ public int exec(HashMap references) throws Exception {
+ //System.out.println("in exec() status = " + translateStatus(status) + "...");
+ if(status < Command.CHILDREN_PROCESSED) {
+ if(status < Command.COMMAND_EXECUTED) {
+ if(status < Command.CHILDREN_FILTERED) {
+ status = doBeforeRun(references);
+ //System.out.println("after doBeforeRun() status = " + translateStatus(status));
+ }
+ if(status == Command.CHILDREN_FILTERED) {
+ status = doRun(references);
+ //System.out.println("after doRun() status = " + translateStatus(status));
+ }
+ }
+ if(status == Command.COMMAND_EXECUTED) {
+ status = doAfterRun(references);
+ //System.out.println("after doAfterRun() status = " + translateStatus(status));
+ }
+ }
+ //System.out.println("...out of exec() status = " + translateStatus(status));
+ return status;
+ }
+
+ // execute commands in backtrack order
+ public boolean backtrack(HashMap references) throws Exception {
+ for(int i = 0; i < arguments.size(); ++i) {
+ Command arg = (Command) arguments.elementAt(i);
+ arg.backtrack(references);
+ }
+ for(int i = 0; i < operations.size(); ++i) {
+ Command opr = (Command) operations.elementAt(i);
+ opr.backtrack(references);
+ }
+ if(status == Command.CHILDREN_FILTERED) {
+ status = doRun(references);
+ }
+ if(status == Command.COMMAND_EXECUTED) {
+ status = doAfterRun(references);
+ return (getStatus() == Command.CHILDREN_PROCESSED);
+ } else {
+ return false;
+ }
+ }
+
+ // put command in one of two collections - arguments ot operations
+ private int doBeforeRun(HashMap references) throws Exception {
+ if(status == Command.INITIALIZED) {
+ for(int i = 0; i < commands.size(); ++i) {
+ Command cmd = (Command) commands.elementAt(i);
+ Vector dest = operations;
+ if(cmd.isExecutable()) {
+ dest = arguments;
+ }
+ dest.add(cmd);
+ }
+ return Command.CHILDREN_FILTERED;
+ } else {
+ return status;
+ }
+ }
+
+ // run command
+ private int doRun(HashMap references) throws Exception {
+ if(status == Command.CHILDREN_FILTERED) {
+ if(isRoot()) {
+ result = new Argument(decoder);
+ //System.out.println("doRun(): result is decoder...");
+ return Command.COMMAND_EXECUTED;
+ }
+
+ if(isNull()) {
+ result = new Argument(null);
+ //System.out.println("doRun(): result is null...");
+ return Command.COMMAND_EXECUTED;
+ }
+
+ if(ctx != null && ctx.isArray() && (ctx.getResultValue() == null)
+ && !isExecutable()) {
+ //System.out.println("doRun(): context is array...");
+ return status;
+ }
+
+ Object target = getTarget(references);
+ if(target == null) {
+ //System.out.println("doRun(): target is null...");
+ return status;
+ } else {
+ if(target instanceof Class) {
+ //System.out.println("doRun(): target = " + ((Class)target).getName());
+ } else {
+ //System.out.println("doRun(): target = " + target.getClass().getName());
+ }
+ if(isReference()) {
+ result = getReferencedArgument(references);
+ //System.out.println("doRun(): reference - result is " + result.getType());
+ } else {
+ String methodName = getMethodName(references);
+ //System.out.println("doRun(): methodName = " + methodName);
+ Argument[] arguments = getArguments();
+ if(arguments == null) return status;
+ //System.out.println("doRun(): args number is " + arguments.length);
+ for(int i = 0; i < arguments.length; ++i) {
+ if(arguments[i] != null) {
+ //System.out.println("doRun(): arg [" + i + "] = " + arguments[i].getType());
+ } else {
+ //System.out.println("doRun(): arg [" + i + "] = null");
+ }
+ }
+
+ Expression expr = new Expression(target, methodName,
+ getArgumentsValues());
+ result = new Argument(expr.getValue());
+
+ if(isPrimitiveClassName(getTagName()))
+ result.setType(getPrimitiveClass(tagName));
+
+ //System.out.println("doRun(): method call - result is " + result.getType());
+ }
+ return Command.COMMAND_EXECUTED;
+ }
+ } else return status;
+ }
+
+ // run child commands
+ private int doAfterRun(HashMap references) throws Exception {
+ if(status == Command.COMMAND_EXECUTED) {
+ //System.out.println("doAfterRun(): command " + getResultType() + " processed...");
+ Vector toBeRemoved = new Vector();
+ try {
+ Statement[] statements = null;
+
+ for(int i = 0; i < operations.size(); ++i) {
+ Command cmd = (Command) operations.elementAt(i);
+
+ if(cmd.isArrayElement()) {
+
+ if(cmd.isResolved()) {
+ if(statements == null) {
+ statements = new Statement[operations.size()];
+ }
+ statements[i] = new Statement(getResultValue(),
+ "set", new Object[] {
+ new Integer(i), cmd.getResultValue()} );
+ if( (i + 1) == operations.size() ) {
+ for(int j = 0; j < operations.size(); ++j) {
+ statements[j].execute();
+ }
+ toBeRemoved.addAll(operations);
+ }
+ } else {
+ break;
+ }
+
+ } else {
+ // since the call is Array.set()
+ if(!isArray()) {
+ cmd.setTarget(getResultValue());
+ }
+ cmd.exec(references);
+
+ if(cmd.isResolved()) {
+ //System.out.println("doAfterRun(): cmd = " + cmd.methodName + " is resolved");
+ toBeRemoved.add(cmd);
+ } else {
+ //System.out.println("doAfterRun(): cmd = " + cmd.methodName + " is unresolved");
+ break;
+ }
+
+ }
+
+ }
+ } catch (Exception e) {
+ throw new Exception(e);
+ } finally {
+ operations.removeAll(toBeRemoved);
+ }
+
+ if(operations.size() == 0) {
+ //System.out.println("doAfterRun(): command " + getResultType() + " completely processed.");
+ } else {
+ //System.out.println("doAfterRun(): command " + getResultType() + " contains incomplete " +
+ //operations.size() + " commands.");
+ }
+ return (operations.size() == 0) ? Command.CHILDREN_PROCESSED
+ : status;
+ } else return status;
+ }
+
+ // Result accessors
+
+ // Return result - Argument class
+ public Argument getResult() {
+ return result;
+ }
+
+ // Returns result value
+ public Object getResultValue() {
+ return (result != null) ? result.getValue() : null;
+ }
+
+ // Returns result type
+ public Class getResultType() throws ClassNotFoundException {
+ return (result != null) ? result.getType() : null;
+ }
+
+ // accessors to XML tags and attrs
+ public boolean hasAttr(String name) {
+ return attrs.get(name) != null;
+ }
+
+ public String getAttr(String name) {
+ return (String) attrs.get(name);
+ }
+
+ public boolean isTag(String name) {
+ return tagName.equals(name);
+ }
+
+ public boolean hasAttr(String name, String value) {
+ return value.equals(attrs.get(name));
+ }
+
+ public String getTagName() {
+ return tagName;
+ }
+
+ // Checks if the object is primitive - int, float, etc...
+ private boolean isPrimitive() {
+ return isPrimitiveClassName(tagName);
+ }
+
+ // Checks if the object is constructor
+ private boolean isConstructor() {
+ return isPrimitive() || !isStaticMethod() && !isMethod()
+ && !isProperty() && !isField() && !isArray() && !isReference();
+ }
+
+ // Checks if the command is static method
+ private boolean isStaticMethod() {
+ return isTag("object") && hasAttr("method") || isTag("class");
+ }
+
+ // Checks if the command is public method
+ private boolean isMethod() {
+ return isTag("void") && (hasAttr("method") || hasAttr("index"));
+ }
+
+ // Check if the command relates to property - getter ot setter depends on
+ // number of args
+ private boolean isProperty() {
+ return isTag("void") && hasAttr("property");
+ }
+
+ // Check if the command is field accessor
+ private boolean isField() {
+ return isTag("object") && hasAttr("field");
+ }
+
+ // Check if the command is array
+ private boolean isArray() {
+ return isTag("array");
+ }
+
+ // Check if the command is array element
+ private boolean isArrayElement() {
+ return (ctx != null) && (ctx.isArray()) && isExecutable();
+ }
+
+ private boolean isReference() {
+ return hasAttr("idref");
+ }
+
+ // Check if the command is root object
+ private boolean isRoot() {
+ return isTag("java");
+ }
+
+ // Check if the command is null
+ private boolean isNull() {
+ return isTag("null");
+ }
+
+ // Checks if the command could generate object
+ public boolean isExecutable() {
+ boolean result = isTag("object") || isTag("void")
+ && hasAttr("class") && hasAttr("method")
+ || isTag("array") || isPrimitive()
+ || isTag("class") || isTag("null");
+ return result;
+ }
+
+ private Argument getReferencedArgument(HashMap references) {
+ return ((Command) references.get(getAttr("idref"))).getResult();
+ }
+
+ // get a target through tag and attrs analysis
+ private Object getTarget(HashMap references) throws Exception {
+ if(target == null){
+ if(isReference()) {
+ Command cmd = (Command) references.get(getAttr("idref"));
+ target = (cmd != null) ? cmd.getResultValue() : null;
+ } else if(isExecutable()) {
+ String className = null;
+
+ if(isPrimitive()) {
+ className = getPrimitiveClassName(tagName);
+ } else if(isTag("class")) {
+ className = getPrimitiveClassName(tagName);
+ } else if(isConstructor() || isStaticMethod() || isField()) {
+ className = getAttr("class");
+ } else if(isArray()) {
+ className = getAttr("class");
+ Class componentType = isPrimitiveClassName(className)
+ ? getPrimitiveClass(className)
+ : Class.forName(className, true,
+ Thread.currentThread().getContextClassLoader());
+ className = Array.newInstance(
+ componentType, 0).getClass().getName();
+ }
+
+ if(className != null) {
+ target = Class.forName(className, true,
+ Thread.currentThread().getContextClassLoader());
+
+ if(isField()) {
+ String fieldName = getAttr("field");
+ target = ((Class) target).getField(fieldName);
+ }
+ } else {
+ throw new Exception("target is not generated: classname "
+ + className + " is not found");
+ }
+ } else if(ctx.isArray()) {
+ //target = ctx.getTarget(references);
+ target = Class.forName("java.lang.reflect.Array");
+ }
+ }
+ return target;
+ }
+
+ // set target to execute command on
+ private void setTarget(Object target) {
+ this.target = target;
+ }
+
+ // Return a method name of command
+ private String getMethodName(HashMap references)
+ throws NoSuchMethodException, IntrospectionException, Exception
+ {
+ if(methodName == null) {
+ String methodValue = null;
+ if(isTag("class")) {
+ addArgument(new Argument(String.class, data), 0);
+ methodValue = "forName";
+ } else if(isPrimitive()) {
+ if(isTag("char")) {
+ if(data.length() != 1) {
+ throw new IntrospectionException("Cannot convert" + data
+ + " to char");
+ } else {
+ addArgument(new Argument(char.class, new Character(
+ data.charAt(0))), 0);
+ }
+ } else {
+ addArgument(new Argument(String.class, data), 0);
+ }
+ methodValue = "new";
+ } else if(isConstructor() || hasAttr("method", "new")) {
+ methodValue = "new";
+ } else if(isArray()) {
+ methodValue = "new";
+ int length = hasAttr("length") ? Integer.parseInt(
+ getAttr("length")) : getArgumentsNumber();
+ copyArgumentsToCommands();
+ addArgument(new Argument(int.class, new Integer(length)), 0);
+ } else if(isTag("class")) {
+ methodValue = "forName";
+ } else if(hasAttr("property")) {
+ String propertyValue = getAttr("property");
+ if(hasAttr("index")) {
+ addArgument(new Argument(int.class, new Integer(
+ getAttr("index"))), 0);
+ }
+
+ BeanInfo beanInfo = Introspector.getBeanInfo(getTarget(
+ references).getClass());
+ PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
+
+ boolean methodFound = false;
+ Method method = null;
+ for(int i = 0; i < pds.length; ++i) {
+ PropertyDescriptor pd = pds[i];
+ if(propertyValue.equals(pd.getName())) {
+ int argsNum = getArgumentsNumber();
+ if(hasAttr("index")) {
+ IndexedPropertyDescriptor ipd =
+ (IndexedPropertyDescriptor) pd;
+ if(argsNum == 1) {
+ method = ipd.getIndexedReadMethod();
+ } else if(argsNum == 0) {
+ method = ipd.getReadMethod();
+ }
+ } else {
+ method = pd.getReadMethod();
+ }
+
+ if(method != null)
+ methodFound = matchMethodParams(method, references);
+
+ if(methodFound == false) {
+ if(hasAttr("index")) {
+ IndexedPropertyDescriptor ipd =
+ (IndexedPropertyDescriptor) pd;
+ if (argsNum == 2) {
+ method = ipd.getIndexedWriteMethod();
+ } else if(argsNum == 1) {
+ method = ipd.getWriteMethod();
+ }
+ } else {
+ method = pd.getWriteMethod();
+ }
+ }
+
+ if(method != null)
+ methodFound = matchMethodParams(method, references);
+ }
+ }
+
+ if(method == null) {
+ throw new NoSuchMethodException("for property "
+ + propertyValue + " no getter(setter) is found");
+ } else {
+ methodValue = method.getName();
+ }
+ } else if(hasAttr("method")) {
+ if(hasAttr("index"))
+ addArgument(new Argument(int.class, Integer.valueOf(
+ getAttr("index"))), 0);
+ methodValue = getAttr("method");
+ } else if(hasAttr("index")) {
+ addArgument(new Argument(int.class, Integer.valueOf(
+ getAttr("index"))), 0);
+ methodValue = getArgumentsNumber() > 1 ? "set" : "get";
+ if(ctx.isArray()) {
+ addArgument(ctx.getResult(), 0);
+ }
+ } else if(hasAttr("field")) {
+ addArgument(
+ new Argument(
+ Class.forName(
+ getAttr("class"), true,
+ Thread.currentThread().getContextClassLoader()
+ )
+ ),
+ 0
+ );
+
+ methodValue = "get";
+ } else {
+ throw new Exception(
+ "method name is not generated: error in "
+ + "getMethodName()");
+ }
+ methodName = methodValue;
+ }
+ return methodName;
+ }
+
+ // return a list of arguments as of Argument type
+ private Argument[] getArguments() {
+ Argument[] args = new Argument[auxArguments.size() + arguments.size()];
+ for(int i = 0; i < auxArguments.size(); ++i)
+ args[i] = (Argument) auxArguments.elementAt(i);
+ for(int j = 0; j < arguments.size(); ++j) {
+ Command cmd = (Command) arguments.elementAt(j);
+ if(cmd.getStatus() >= Command.COMMAND_EXECUTED) {
+ args[auxArguments.size() + j] = cmd.getResult();
+ } else {
+ //System.out.println("arg: " + cmd.getResultValue());
+ args = null; break;
+ }
+ }
+ return args;
+ }
+
+ // return argument values
+ private Object[] getArgumentsValues() {
+ Argument[] args = getArguments();
+ Object[] result = new Object[args.length];
+ for(int i = 0; i < args.length; ++i)
+ result[i] = args[i].getValue();
+ return result;
+ }
+
+ // copy arguments to treat as commands
+ private void copyArgumentsToCommands() {
+ Iterator i = arguments.iterator();
+ while(i.hasNext()) {
+ Command cmd = (Command) i.next();
+ cmd.status = Command.CHILDREN_FILTERED;
+ operations.add(cmd);
+ }
+ arguments.clear();
+ }
+
+ // return number of arguments
+ private int getArgumentsNumber() {
+ return auxArguments.size() + arguments.size();
+ }
+
+ // return number of commands
+ private int getOperationsNumber() {
+ return operations.size();
+ }
+
+ // add argument to the beginning of arguments
+ private void addArgument(Argument argument, int idx) {
+ auxArguments.insertElementAt(argument, idx);
+ }
+
+ // Check if the name of class is primitive
+ public static boolean isPrimitiveClassName(String className) {
+ return className.equalsIgnoreCase("boolean")
+ || className.equalsIgnoreCase("byte")
+ || className.equalsIgnoreCase("char")
+ || className.equalsIgnoreCase("short")
+ || className.equalsIgnoreCase("int")
+ || className.equalsIgnoreCase("long")
+ || className.equalsIgnoreCase("float")
+ || className.equalsIgnoreCase("double")
+ || className.equalsIgnoreCase("string");
+ }
+
+ // Transforms a primitive class name
+ private String getPrimitiveClassName(String data) {
+ String shortClassName = null;
+ if(data.equals("int")) {
+ shortClassName = "Integer";
+ } else if (data.equals("char")) {
+ shortClassName = "Character";
+ } else {
+ shortClassName = data.substring(0,1).toUpperCase()
+ + data.substring(1, data.length());
+ }
+ return "java.lang." + shortClassName;
+ }
+
+ public static Class getPrimitiveClass(String className) {
+ Class result = null;
+ if(className.equals("boolean")) {
+ result = boolean.class;
+ } else if(className.equals("byte")) {
+ result = byte.class;
+ } else if(className.equals("char")) {
+ result = char.class;
+ } else if(className.equals("short")) {
+ result = short.class;
+ } else if(className.equals("int")) {
+ result = int.class;
+ } else if(className.equals("long")) {
+ result = long.class;
+ } else if(className.equals("float")) {
+ result = float.class;
+ } else if(className.equals("double")) {
+ result = double.class;
+ } else if(className.equals("string")) {
+ result = String.class;
+ }
+ return result;
+ }
+
+ private boolean matchMethodParams(Method method, HashMap references) {
+ Class[] paramTypes = method.getParameterTypes();
+ Argument[] args = getArguments();
+ if(args == null) return false;
+ boolean result = true;
+ if(paramTypes.length == args.length) {
+ for(int j = 0; j < paramTypes.length; ++j) {
+ //System.out.println("paramTypes[j] = " + paramTypes[j]);
+ //System.out.println("args[j] = " + args[j].getType());
+
+ boolean isAssignable = (args[j].getType() == null)
+ ? !paramTypes[j].isPrimitive()
+ : paramTypes[j].isAssignableFrom(args[j].getType());
+
+ //System.out.println("args[j] = " + args[j].getType());
+
+ if(!isAssignable) {
+ result = false;
+ break;
+ }
+ }
+ } else result = false;
+ return result;
+ }
+
+ public static HashMap parseAttrs(String tagName, Attributes attrs) {
+ HashMap result = new HashMap();
+ if(tagName.equals("object")) {
+ for(int i = 0; i < objectAttrNames.length; ++i) {
+ String name = objectAttrNames[i];
+ String value = attrs.getValue(name);
+ if(value != null) result.put(name, value);
+ }
+ } else if(tagName.equals("void")) {
+ for(int i = 0; i < voidAttrNames.length; ++i) {
+ String name = voidAttrNames[i];
+ String value = attrs.getValue(name);
+ if(value != null) result.put(name, value);
+ }
+ } else if(tagName.equals("array")) {
+ for(int i = 0; i < arrayAttrNames.length; ++i) {
+ String name = arrayAttrNames[i];
+ String value = attrs.getValue(name);
+ if(value != null) result.put(name, value);
+ }
+ } else if(tagName.equals("java")) {
+ for(int i = 0; i < javaAttrNames.length; ++i) {
+ String name = javaAttrNames[i];
+ String value = attrs.getValue(name);
+ if(value != null) result.put(name, value);
+ }
+ }
+ return result;
+ }
+
+ // Auxiliary logging with tabs functions
+ public static void pr(String msg) {
+ //System.out.print(msg);
+ }
+ public static void pr(int tabCount, String msg) {
+ String result = "";
+ for(int i = 0; i < tabCount; ++i) result += '\t';
+ result += msg;
+ //System.out.print(result);
+ }
+ public static void prn(String msg) {
+ //System.out.println(msg);
+ }
+ public static void prn(int tabCount, String msg) {
+ String result = "";
+ for(int i = 0; i < tabCount; ++i) result += '\t';
+ result += msg;
+ //System.out.println(result);
+ }
+
+ public static void printAttrs(
+ int tabCount, String tagName, Attributes attrs) {
+ pr(tabCount, tabCount + ">in <" + tagName);
+ for(int i = 0; i < attrs.getLength(); ++i) {
+ String attrName = attrs.getQName(i);
+ String attrValue = attrs.getValue(i);
+ pr(" " + attrName + "=" + attrValue);
+ }
+ prn(">");
+ }
+
+ private static int initializeStatus(String tagName) {
+ // return tagName.equals("java") ? Command.COMMAND_EXECUTED : Command.INITIALIZED;
+ return Command.INITIALIZED;
+ }
+
+ private static String translateStatus(int status) {
+ String result = "unknown";
+ if(status == Command.INITIALIZED) {
+ result = "intialized";
+ } else if(status == Command.CHILDREN_FILTERED) {
+ result = "children filtered";
+ } else if(status == Command.COMMAND_EXECUTED) {
+ result = "executed";
+ } else if(status == Command.CHILDREN_PROCESSED) {
+ result = "children processed";
+ }
+ return result;
+ }
+
+ private static final String[] objectAttrNames =
+ { "id", "idref", "class", "field", "method", "property", "index" };
+
+ private static final String[] voidAttrNames =
+ { "id", "class", "method", "property", "index" };
+
+ private static final String[] arrayAttrNames = { "id", "class", "length" };
+
+ private static final String[] javaAttrNames = { "version", "class" };
+}