Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/EventSetDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/EventSetDescriptor.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/EventSetDescriptor.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/EventSetDescriptor.java Mon Jul 16 23:30:22 2007
@@ -38,6 +38,10 @@
private boolean unicast;
private boolean inDefaultEventSet = true;
+
+ private Class awtEventListener;
+
+ private Class awtEventAction;
public EventSetDescriptor(Class<?> sourceClass, String eventSetName,
Class<?> listenerType, String listenerMethodName)
@@ -59,7 +63,7 @@
removeListenerMethod = findMethodByPrefix(
sourceClass, "remove", ""); //$NON-NLS-1$ //$NON-NLS-2$
- if (addListenerMethod == null && removeListenerMethod == null) {
+ if (addListenerMethod == null || removeListenerMethod == null) {
throw new IntrospectionException(
Messages.getString("beans.38")); //$NON-NLS-1$
}
@@ -95,7 +99,7 @@
for (String element : listenerMethodNames) {
Method m = findListenerMethodByName(element);
- checkEventType(eventSetName, m);
+ //checkEventType(eventSetName, m);
listenerMethodDescriptors.add(new MethodDescriptor(m));
}
@@ -114,6 +118,28 @@
this.unicast = isUnicastByDefault(addListenerMethod);
}
+ private Method findListenerMethodByName(
+ String listenerMethodName) throws IntrospectionException {
+ Method method = null;
+ Method[] methods = listenerType.getMethods();
+ for (Method m : methods) {
+ if (m.getName().equals(listenerMethodName)) {
+ Class[] paramTypes = m.getParameterTypes();
+ if (paramTypes.length == 1
+ && paramTypes[0].getName().endsWith("Event")) {
+ method = m;
+ break;
+ }
+
+ }
+ }
+ if (null == method) {
+ throw new IntrospectionException(Messages.getString("beans.31", //$NON-NLS-1$
+ listenerMethodName, listenerType.getName()));
+ }
+ return method;
+ }
+
public EventSetDescriptor(String eventSetName, Class<?> listenerType,
Method[] listenerMethods, Method addListenerMethod,
Method removeListenerMethod) throws IntrospectionException {
@@ -136,11 +162,11 @@
for (Method element : listenerMethods) {
// XXX do we need this check?
- //checkEventType(eventSetName, element);
- if (checkMethod(listenerType, element)) {
- this.listenerMethodDescriptors.add(
- new MethodDescriptor(element));
- }
+ // checkEventType(eventSetName, element);
+ // if (checkMethod(listenerType, element)) {
+ this.listenerMethodDescriptors
+ .add(new MethodDescriptor(element));
+ // }
}
}
@@ -164,10 +190,10 @@
Method listenerMethod = element.getMethod();
// XXX
- //checkEventType(eventSetName, listenerMethod);
- if (checkMethod(listenerType, listenerMethod)) {
- this.listenerMethodDescriptors.add(element);
- }
+ // checkEventType(eventSetName, listenerMethod);
+ // if (checkMethod(listenerType, listenerMethod)) {
+ this.listenerMethodDescriptors.add(element);
+ // }
}
}
}
@@ -285,20 +311,9 @@
return inDefaultEventSet;
}
- /**
- * @return type of event associated with the current event set descriptor
- * @throws ClassNotFoundException if event class is not found
- */
- private Class<?> getEventType() throws ClassNotFoundException {
- String listenerTypeName = listenerType.getName();
- String prefix = listenerTypeName.substring(0,
- listenerTypeName.indexOf(
- BeanInfoImpl.extractShortClassName(listenerTypeName)));
- String eventTypeName = prefix + prepareEventTypeName(getName());
-
- return Class.forName(eventTypeName, true, listenerType.getClassLoader());
- }
-
+
+ private static final String AWT_EVENT_PREFIX="java.awt.event.";
+
private boolean checkMethod(Class<?> listenerType, Method listenerMethod)
throws IntrospectionException {
if (listenerMethod != null && listenerType != null &&
@@ -309,28 +324,7 @@
return true;
}
- /**
- * Searches for the method in listener that has the given name. Parameter
- * check is also performed for found methods.
- * @param listenerMethodName name of listener method
- * @return found method if any
- * @throws IntrospectionException if no method is found or other error
- * has occured
- */
- private Method findListenerMethodByName(String listenerMethodName)
- throws IntrospectionException {
- try {
- return listenerType.getMethod(listenerMethodName, getEventType());
- } catch (NoSuchMethodException nsme) {
- throw new IntrospectionException(Messages.getString(
- "beans.31", //$NON-NLS-1$
- listenerMethodName, listenerType.getName()));
- } catch (ClassNotFoundException cnfe) {
- throw new IntrospectionException(Messages.getString(
- "beans.32", listenerType.getName())); //$NON-NLS-1$
- }
- }
-
+
/**
* Searches for {add|remove}Listener methods in the event source.
* Parameter check is also performed.
@@ -343,18 +337,55 @@
String methodName) throws IntrospectionException {
try {
return sourceClass.getMethod(methodName, listenerType);
+ } catch (NoSuchMethodException e) {
+ return findAddRemoveListnerMethodWithLessCheck(sourceClass,
+ methodName, listenerType);
} catch (Exception e) {
- throw new IntrospectionException(
- Messages.getString("beans.31", //$NON-NLS-1$
- methodName, listenerType.getName()));
+ throw new IntrospectionException(Messages.getString("beans.31", //$NON-NLS-1$
+ methodName, listenerType.getName()));
}
}
+
+ private Method findAddRemoveListnerMethodWithLessCheck(
+ Class<?> sourceClass, String methodName, Class listenerTYpe)
+ throws IntrospectionException {
+ String expectedListenerTypeName = listenerType.getName();
+ expectedListenerTypeName = expectedListenerTypeName
+ .substring(expectedListenerTypeName.lastIndexOf(".") + 1);
+ Method method = null;
+ Method[] methods = sourceClass.getMethods();
+ for (Method m : methods) {
+ if (m.getName().equals(methodName)) {
+ Class[] paramTypes = m.getParameterTypes();
+ if (paramTypes.length == 1) {
+// String paramTypeName = paramTypes[0].getName();
+// paramTypeName = paramTypeName.substring(paramTypeName
+// .lastIndexOf(".") + 1);
+// if (paramTypeName.endsWith("Listener")) {
+// paramTypeName = paramTypeName.substring(0,
+// paramTypeName.length() - "Listener".length());
+// if (expectedListenerTypeName.startsWith(paramTypeName)) {
+ method = m;
+ break;
+// }
+// }
+ }
+ }
+ }
+ if (null == method) {
+ throw new IntrospectionException(Messages.getString("beans.31", //$NON-NLS-1$
+ methodName, listenerType.getName()));
+ }
+ return method;
+ }
/**
- * @param sourceClass class of event source
- * @param methodName name of the custom getListeners() method
- * @return found Method object for custom getListener or null if nothing
- * is found
+ * @param sourceClass
+ * class of event source
+ * @param methodName
+ * name of the custom getListeners() method
+ * @return found Method object for custom getListener or null if nothing is
+ * found
*/
private Method findGetListenerMethod(Class<?> sourceClass,
String methodName) {
@@ -368,18 +399,29 @@
private Method findMethodByPrefix(Class<?> sourceClass,
String prefix, String postfix) {
- String shortName = BeanInfoImpl.extractShortClassName(
- listenerType.getName());
+ String shortName = listenerType.getName();
+ if(listenerType.getPackage()!= null){
+ shortName = shortName.substring(
+ listenerType.getPackage().getName().length() + 1);
+ }
String methodName = prefix + shortName + postfix;
-
try {
if (prefix.equals("get")) { //$NON-NLS-1$
return sourceClass.getMethod(methodName);
}
- return sourceClass.getMethod(methodName, listenerType);
} catch (NoSuchMethodException nsme) {
return null;
}
+ Method[] m = sourceClass.getMethods();
+ for(int i = 0; i < m.length; i++){
+ if(m[i].getName().equals(methodName)){
+ Class[] paramTypes = m[i].getParameterTypes();
+ if (paramTypes.length == 1) {
+ return m[i];
+ }
+ }
+ }
+ return null;
}
private static boolean isUnicastByDefault(Method addMethod) {
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Introspector.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Introspector.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Introspector.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Introspector.java Mon Jul 16 23:30:22 2007
@@ -83,14 +83,15 @@
return getBeanInfo(beanClass, stopClass, false, false);
}
- public static synchronized void setBeanInfoSearchPath(String[] searchPath) {
+ public static void setBeanInfoSearchPath(String[] searchPath) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPropertiesAccess();
}
-
- path = searchPath;
+ synchronized(Introspector.class) {
+ path = searchPath;
+ }
}
public static synchronized String[] getBeanInfoSearchPath() {
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PersistenceDelegate.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PersistenceDelegate.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PersistenceDelegate.java Mon Jul 16 23:30:22 2007
@@ -1,76 +1,123 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-package java.beans;
-import org.apache.harmony.beans.internal.nls.Messages;
+package java.beans;
+/**
+ * <code>PersistenceDelegate</code> instances write received bean objects to
+ * encoders in the form of expressions and statements, which can be evaluated or
+ * executed to reconstruct the recorded bean objects in a new environment during
+ * decoding. Expressions are usually used to instantiate bean objects in the new
+ * environment, and statements are used to initialize their properties if
+ * necessary. As a result, the reconstructed bean objects become equivalent to
+ * the original recorded ones in terms of their public states.
+ *
+ */
public abstract class PersistenceDelegate {
- protected void initialize(Class<?> type, Object oldInstance,
- Object newInstance, Encoder out) {
-
- if (type == null) {
- throw new NullPointerException(Messages.getString("beans.4B")); //$NON-NLS-1$
- }
+ /**
+ * Default constructor.
+ */
+ public PersistenceDelegate() {
+ // empty
+ }
- if (out != null) {
- PersistenceDelegate pd = out.getPersistenceDelegate(type
- .getSuperclass());
-
- if (pd != null) {
- try {
- pd.initialize(type, oldInstance, newInstance, out);
- } catch (StackOverflowError err) {
- // circular redundancy
- // we should catch in order to be compatible with RI
- }
- }
- } else {
- throw new NullPointerException(
- Messages.getString("beans.4C")); //$NON-NLS-1$
+ /**
+ * Produces a series of expressions and statements for the initialization of
+ * a bean object's properties. The default implementation simply invokes the
+ * initialization provided by the super class's
+ * <code>PersisteneceDelegate</code> instance.
+ *
+ * @param type
+ * the type of the bean
+ * @param oldInstance
+ * the original bean object to be recorded
+ * @param newInstance
+ * the simmulating new bean object to be initialized
+ * @param enc
+ * the encoder to write the outputs to
+ */
+ protected void initialize(Class<?> type, Object oldInstance,
+ Object newInstance, Encoder enc) {
+ Class c = type.getSuperclass();
+ if (null != c) {
+ PersistenceDelegate pd = enc.getPersistenceDelegate(c);
+ pd.initialize(c, oldInstance, newInstance, enc);
}
}
- protected abstract Expression instantiate(Object oldInstance, Encoder out);
-
- protected boolean mutatesTo(Object oldInstance, Object newInstance) {
- boolean bothInstancesAreNull = (oldInstance == null)
- && (newInstance == null);
-
- if (bothInstancesAreNull) {
+ /**
+ * Constructs an expression for instantiating an object of the same type as
+ * the old instance. Any exceptions occured during this process could be
+ * reported to the exception listener registered in the given encoder.
+ *
+ * @param oldInstance
+ * the old instance
+ * @param enc
+ * the encoder that wants to record the old instance
+ * @return an expression for instantiating an object of the same type as the
+ * old instance
+ */
+ protected abstract Expression instantiate(Object oldInstance, Encoder enc);
+
+ /**
+ * Determines whether one object mutates to the other object. One object is
+ * considered able to mutate to another object if they are indistinguishable
+ * in terms of behaviors of all public APIs. The default implementation here
+ * is to return true only if the two objects are instances of the same
+ * class.
+ *
+ * @param o1
+ * one object
+ * @param o2
+ * the other object
+ * @return true if second object mutates to the first object, otherwise
+ * false
+ */
+ protected boolean mutatesTo(Object o1, Object o2) {
+ if (null == o1 || null == o2 ) {
return false;
}
- return (oldInstance != null) && (newInstance != null) ? oldInstance
- .getClass() == newInstance.getClass() : false;
+ return o1.getClass() == o2.getClass();
}
+ /**
+ * Writes a bean object to the given encoder. First it is checked whether
+ * the simulating new object can be mutated to the old instance. If yes, it
+ * is initialized to produce a series of expressions and statements that can
+ * be used to restore the old instance. Otherwise, remove the new object in
+ * the simulating new environment and writes an expression that can
+ * instantiate a new instance of the same type as the old one to the given
+ * encoder.
+ *
+ * @param oldInstance
+ * the old instance to be written
+ * @param out
+ * the encoder that the old instance will be written to
+ */
public void writeObject(Object oldInstance, Encoder out) {
- // nulls are covered by NullPersistenceDelegate
- assert oldInstance != null;
-
Object newInstance = out.get(oldInstance);
-
if (mutatesTo(oldInstance, newInstance)) {
initialize(oldInstance.getClass(), oldInstance, newInstance, out);
} else {
- out.remove(oldInstance);
-
- out.writeExpression(instantiate(oldInstance, out));
+ out.remove(oldInstance);
+ Expression exp = instantiate(oldInstance, out);
+ out.writeExpression(exp);
newInstance = out.get(oldInstance);
if (newInstance != null) {
@@ -79,4 +126,6 @@
}
}
}
+
}
+
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyDescriptor.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyDescriptor.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyDescriptor.java Mon Jul 16 23:30:22 2007
@@ -21,6 +21,8 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Vector;
+
+import org.apache.harmony.beans.BeansUtils;
import org.apache.harmony.beans.internal.nls.Messages;
public class PropertyDescriptor extends FeatureDescriptor {
@@ -171,6 +173,15 @@
&& constrainedPropertyAreEqual;
}
return result;
+ }
+
+ @Override
+ public int hashCode() {
+ return BeansUtils.getHashCode(getter) + BeansUtils.getHashCode(setter)
+ + BeansUtils.getHashCode(getPropertyType())
+ + BeansUtils.getHashCode(getPropertyEditorClass())
+ + BeansUtils.getHashCode(isBound())
+ + BeansUtils.getHashCode(isConstrained());
}
public void setPropertyEditorClass(Class<?> propertyEditorClass) {
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyEditorManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyEditorManager.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyEditorManager.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyEditorManager.java Mon Jul 16 23:30:22 2007
@@ -99,7 +99,7 @@
return editor;
}
- public static synchronized void setEditorSearchPath(String[] apath) {
+ public static void setEditorSearchPath(String[] apath) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPropertiesAccess();
@@ -107,7 +107,9 @@
if(apath == null){
apath = new String[0];
}
- path = apath;
+ synchronized(PropertyEditorManager.class){
+ path = apath;
+ }
}
public static synchronized String[] getEditorSearchPath() {
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLDecoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLDecoder.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLDecoder.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLDecoder.java Mon Jul 16 23:30:22 2007
@@ -1,142 +1,541 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
+
package java.beans;
-import java.io.IOException;
import java.io.InputStream;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import java.util.Vector;
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Stack;
+
+import javax.xml.parsers.SAXParserFactory;
-import org.apache.harmony.beans.Handler;
-import org.xml.sax.InputSource;
+import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+/**
+ * <code>XMLDecoder</code> reads objects from xml created by
+ * <code>XMLEncoder</code>.
+ * <p>The API is similar to <code>ObjectInputStream</code>.</p>
+ *
+ */
public class XMLDecoder {
- private InputStream is = null;
+ private ClassLoader defaultClassLoader = null;
+
+ private static class DefaultExceptionListener implements ExceptionListener {
+
+ public void exceptionThrown(Exception e) {
+ e.printStackTrace();
+ System.err.println("Continue...");
+ }
+ }
- private Object owner = null;
+ private class SAXHandler extends DefaultHandler {
- private ExceptionListener exceptionListener = null;
+ boolean inJavaElem = false;
- private final Vector<Object> objects = new Vector<Object>();
+ HashMap idObjMap = new HashMap();
- private Iterator<Object> iterator = null;
-
- private ClassLoader classLoader = null;
+ public void characters(char[] ch, int start, int length)
+ throws SAXException {
+ if (!inJavaElem) {
+ return;
+ }
+ if (readObjs.size() > 0) {
+ Elem elem = (Elem) readObjs.peek();
+ if (elem.isBasicType) {
+ String str = new String(ch, start, length);
+ elem.methodName = elem.methodName == null ? str
+ : elem.methodName + str;
+ }
+ }
+ }
- public XMLDecoder(InputStream is, Object owner,
- ExceptionListener exceptionListener, ClassLoader cl) {
- this.is = is;
- this.owner = owner;
- this.exceptionListener = exceptionListener;
- this.classLoader = cl;
+ public void startElement(String uri, String localName, String qName,
+ Attributes attributes) throws SAXException {
+ if (!inJavaElem) {
+ if ("java".equals(qName)) {
+ inJavaElem = true;
+ } else {
+ listener.exceptionThrown(new Exception(
+ "unknown root element: " + qName));
+ }
+ return;
+ }
+
+ if ("object".equals(qName)) {
+ startObjectElem(attributes);
+ } else if ("array".equals(qName)) {
+ startArrayElem(attributes);
+ } else if ("void".equals(qName)) {
+ startVoidElem(attributes);
+ } else if ("boolean".equals(qName) || "byte".equals(qName)
+ || "char".equals(qName) || "class".equals(qName)
+ || "double".equals(qName) || "float".equals(qName)
+ || "int".equals(qName) || "long".equals(qName)
+ || "short".equals(qName) || "string".equals(qName)
+ || "null".equals(qName)) {
+ startBasicElem(qName, attributes);
+ }
+ }
+
+ private void startObjectElem(Attributes attributes) throws SAXException {
+ Elem elem = new Elem();
+ elem.isExpression = true;
+ elem.id = attributes.getValue("id");
+ elem.idref = attributes.getValue("idref");
+ if (elem.idref == null) {
+ obtainTarget(elem, attributes);
+ obtainMethod(elem, attributes);
+ }
+
+ readObjs.push(elem);
+ }
+
+ private void obtainTarget(Elem elem, Attributes attributes) {
+ String className = attributes.getValue("class");
+ if (className != null) {
+ try {
+ elem.target = classForName(className);
+ } catch (ClassNotFoundException e) {
+ listener.exceptionThrown(e);
+ }
+ } else {
+ Elem parent = latestUnclosedElem();
+ if(parent == null) {
+ elem.target = owner;
+ return;
+ }
+ elem.target = execute(parent);
+ }
+ }
+
+ private void obtainMethod(Elem elem, Attributes attributes) {
+ elem.methodName = attributes.getValue("method");
+ if (elem.methodName != null) {
+ return;
+ }
+
+ elem.methodName = attributes.getValue("property");
+ if (elem.methodName != null) {
+ elem.fromProperty = true;
+ return;
+ }
+
+ elem.methodName = attributes.getValue("index");
+ if (elem.methodName != null) {
+ elem.fromIndex = true;
+ return;
+ }
+
+ elem.methodName = attributes.getValue("field");
+ if (elem.methodName != null) {
+ elem.fromField = true;
+ return;
+ }
+
+ elem.methodName = attributes.getValue("owner");
+ if (elem.methodName != null) {
+ elem.fromOwner = true;
+ return;
+ }
+
+ elem.methodName = "new"; // default method name
+ }
+
+ private Class classForName(String className)
+ throws ClassNotFoundException {
+ if ("boolean".equals(className)) {
+ return Boolean.TYPE;
+ } else if ("byte".equals(className)) {
+ return Byte.TYPE;
+ } else if ("char".equals(className)) {
+ return Character.TYPE;
+ } else if ("double".equals(className)) {
+ return Double.TYPE;
+ } else if ("float".equals(className)) {
+ return Float.TYPE;
+ } else if ("int".equals(className)) {
+ return Integer.TYPE;
+ } else if ("long".equals(className)) {
+ return Long.TYPE;
+ } else if ("short".equals(className)) {
+ return Short.TYPE;
+ } else {
+ return Class.forName(className, true,
+ defaultClassLoader == null ? Thread.currentThread()
+ .getContextClassLoader() : defaultClassLoader);
+ }
+ }
+
+ private void startArrayElem(Attributes attributes) {
+ Elem elem = new Elem();
+ elem.isExpression = true;
+ elem.id = attributes.getValue("id");
+ try {
+ // find componet class
+ Class compClass = classForName(attributes.getValue("class"));
+ // find length
+ int length = Integer.parseInt(attributes.getValue("length"));
+ // execute, new array instance
+ elem.result = Array.newInstance(compClass, length);
+ elem.isExecuted = true;
+ } catch (Exception e) {
+ listener.exceptionThrown(e);
+ }
+ readObjs.push(elem);
+ }
+
+ private void startVoidElem(Attributes attributes) {
+ Elem elem = new Elem();
+ elem.id = attributes.getValue("id");
+ obtainTarget(elem, attributes);
+ obtainMethod(elem, attributes);
+ readObjs.push(elem);
+ }
+
+ private void startBasicElem(String tagName, Attributes attributes) {
+ Elem elem = new Elem();
+ elem.isBasicType = true;
+ elem.isExpression = true;
+ elem.id = attributes.getValue("id");
+ elem.idref = attributes.getValue("idref");
+ elem.target = tagName;
+ readObjs.push(elem);
+ }
+
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException {
+ if (!inJavaElem) {
+ return;
+ }
+ if ("java".equals(qName)) {
+ inJavaElem = false;
+ return;
+ }
+ // find the elem to close
+ Elem toClose = latestUnclosedElem();
+ // make sure it is executed
+ execute(toClose);
+ // set to closed
+ toClose.isClosed = true;
+ // pop it and its children
+ while (readObjs.pop() != toClose) {
+ //
+ }
+ // push back expression
+ if (toClose.isExpression) {
+ readObjs.push(toClose);
+ }
+ }
+
+ private Elem latestUnclosedElem() {
+ for (int i = readObjs.size() - 1; i >= 0; i--) {
+ Elem elem = (Elem) readObjs.get(i);
+ if (!elem.isClosed) {
+ return elem;
+ }
+ }
+ return null;
+ }
+
+ private Object execute(Elem elem) {
+ if (elem.isExecuted) {
+ return elem.result;
+ }
+
+ // execute to obtain result
+ try {
+ if (elem.idref != null) {
+ elem.result = idObjMap.get(elem.idref);
+ } else if (elem.isBasicType) {
+ elem.result = executeBasic(elem);
+ } else {
+ elem.result = executeCommon(elem);
+ }
+ } catch (Exception e) {
+ listener.exceptionThrown(e);
+ }
+
+ // track id
+ if (elem.id != null) {
+ idObjMap.put(elem.id, elem.result);
+ }
+
+ elem.isExecuted = true;
+ return elem.result;
+ }
+
+ private Object executeCommon(Elem elem) throws Exception {
+ // pop args
+ ArrayList args = new ArrayList(5);
+ while (readObjs.peek() != elem) {
+ Elem argElem = (Elem) readObjs.pop();
+ args.add(0, argElem.result);
+ }
+ // decide method name
+ String method = elem.methodName;
+ if (elem.fromProperty) {
+ method = (args.size() == 0 ? "get" : "set")
+ + capitalize(method);
+ }
+ if (elem.fromIndex) {
+ Integer index = Integer.valueOf(method);
+ args.add(0, index);
+ method = args.size() == 1 ? "get" : "set";
+ }
+ if(elem.fromField) {
+ Field f = ((Class)elem.target).getField(method);
+ return (new Expression(f, "get", new Object[] {null})).getValue();
+ }
+ if(elem.fromOwner) {
+ return owner;
+ }
+
+ if(elem.target == owner) {
+ if("getOwner".equals(method)) {
+ return owner;
+ } else {
+ Class[] c = new Class[args.size()];
+ for(int i = 0; i < args.size(); i++) {
+ c[i] = args.get(i).getClass();
+ }
+ Method m = owner.getClass().getMethod(method, c);
+ return m.invoke(owner, args.toArray());
+ }
+ }
+
+ // execute
+ Expression exp = new Expression(elem.target, method, args.toArray());
+ return exp.getValue();
+ }
+
+ private String capitalize(String str) {
+ StringBuffer buf = new StringBuffer(str);
+ buf.setCharAt(0, Character.toUpperCase(buf.charAt(0)));
+ return buf.toString();
+ }
+
+ private Object executeBasic(Elem elem) throws Exception {
+ String tag = (String) elem.target;
+ String value = elem.methodName;
+
+ if ("null".equals(tag)) {
+ return null;
+ } else if ("string".equals(tag)) {
+ return value;
+ } else if ("class".equals(tag)) {
+ return classForName(value);
+ } else if ("boolean".equals(tag)) {
+ return Boolean.valueOf(value);
+ } else if ("byte".equals(tag)) {
+ return Byte.valueOf(value);
+ } else if ("char".equals(tag)) {
+ return new Character(value.charAt(0));
+ } else if ("double".equals(tag)) {
+ return Double.valueOf(value);
+ } else if ("float".equals(tag)) {
+ return Float.valueOf(value);
+ } else if ("int".equals(tag)) {
+ return Integer.valueOf(value);
+ } else if ("long".equals(tag)) {
+ return Long.valueOf(value);
+ } else if ("short".equals(tag)) {
+ return Short.valueOf(value);
+ } else {
+ throw new Exception("Unknown tag of basic type: " + tag);
+ }
+ }
+
+ public void error(SAXParseException e) throws SAXException {
+ listener.exceptionThrown(e);
+ }
+
+ public void fatalError(SAXParseException e) throws SAXException {
+ listener.exceptionThrown(e);
+ }
+
+ public void warning(SAXParseException e) throws SAXException {
+ listener.exceptionThrown(e);
+ }
}
- public XMLDecoder(InputStream is, Object owner,
- ExceptionListener exceptionListener) {
- this.is = is;
- this.owner = owner;
- this.exceptionListener = exceptionListener;
+ private static class Elem {
+ String id;
+
+ String idref;
+
+ boolean isExecuted;
+
+ boolean isExpression;
+
+ boolean isBasicType;
+
+ boolean isClosed;
+
+ Object target;
+
+ String methodName;
+
+ boolean fromProperty;
+
+ boolean fromIndex;
+
+ boolean fromField;
+
+ boolean fromOwner;
+
+ Object result;
}
- public XMLDecoder(InputStream is, Object owner) {
- this.is = is;
- this.owner = owner;
+ private InputStream inputStream;
+
+ private ExceptionListener listener;
+
+ private Object owner;
+
+ private Stack readObjs = new Stack();
+
+ private int readObjIndex = 0;
+
+ /**
+ * Create a decoder to read from specified input stream.
+ *
+ * @param inputStream an input stream of xml
+ */
+ public XMLDecoder(InputStream inputStream) {
+ this(inputStream, null, null);
}
- public XMLDecoder(InputStream is) {
- this.is = is;
+ /**
+ * Create a decoder to read from specified input stream.
+ *
+ * @param inputStream an input stream of xml
+ * @param owner the owner of this decoder
+ */
+ public XMLDecoder(InputStream inputStream, Object owner) {
+ this(inputStream, owner, null);
}
- public void setOwner(Object owner) {
+ /**
+ * Create a decoder to read from specified input stream.
+ *
+ * @param inputStream an input stream of xml
+ * @param owner the owner of this decoder
+ * @param listener listen to the exceptions thrown by the decoder
+ */
+ public XMLDecoder(InputStream inputStream, Object owner,
+ ExceptionListener listener) {
+ if (inputStream == null) {
+ throw new IllegalArgumentException("Input stream cannot be null");
+ }
+ if (listener == null) {
+ listener = new DefaultExceptionListener();
+ }
+ this.inputStream = inputStream;
this.owner = owner;
- }
+ this.listener = listener;
- public Object readObject() {
try {
- if (iterator == null) {
- initialize();
- }
- return iterator.next();
- } catch (NoSuchElementException nsee) {
- throw new ArrayIndexOutOfBoundsException();
+ SAXParserFactory.newInstance().newSAXParser().parse(inputStream,
+ new SAXHandler());
+ } catch (Exception e) {
+ listener.exceptionThrown(e);
}
}
-
- public Object getOwner() {
- return owner;
+
+ public XMLDecoder(InputStream inputStream, Object owner,
+ ExceptionListener listener, ClassLoader cl) {
+ this(inputStream, owner, listener);
+ defaultClassLoader = cl;
}
- public void setExceptionListener(ExceptionListener exceptionListener) {
- this.exceptionListener = exceptionListener;
+ /**
+ * Close the input stream of xml data.
+ */
+ public void close() {
+ try {
+ inputStream.close();
+ } catch (Exception e) {
+ listener.exceptionThrown(e);
+ }
}
+ /**
+ * Returns the exception listener.
+ * @return the exception listener
+ */
public ExceptionListener getExceptionListener() {
- return exceptionListener;
+ return listener;
}
- public void close() {
- try {
- is.close();
- } catch (IOException ioe) {
- handleException(ioe);
- }
+ /**
+ * Returns the owner of this decoder.
+ * @return the owner of this decoder
+ */
+ public Object getOwner() {
+ return owner;
}
- private void handleException(Exception e) {
- if (exceptionListener != null) {
- exceptionListener.exceptionThrown(e);
+ /**
+ * Reads the next object.
+ *
+ * @return the next object
+ * @exception ArrayIndexOutOfBoundsException if no more objects to read
+ */
+ public Object readObject() {
+ if (readObjIndex >= readObjs.size()) {
+ throw new ArrayIndexOutOfBoundsException("no more objects to read");
+ }
+ Elem elem = (Elem) readObjs.get(readObjIndex);
+ if (!elem.isClosed) {
+ // bad element, error occured while parsing
+ throw new ArrayIndexOutOfBoundsException("no more objects to read");
}
+ readObjIndex++;
+ return elem.result;
}
- private void initialize() {
- ClassLoader oldCL = null;
-
- try {
- String saxParserClassName = System
- .getProperty("org.xml.sax.driver"); //$NON-NLS-1$
-
- if (saxParserClassName == null) {
- saxParserClassName = "org.apache.xerces.parsers.SAXParser"; //$NON-NLS-1$
- }
- XMLReader xmlReader = XMLReaderFactory
- .createXMLReader(saxParserClassName);
- xmlReader.setContentHandler(new Handler(this, objects));
- if (classLoader != null) {
- oldCL = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(classLoader);
- }
- xmlReader.parse(new InputSource(is));
- if (classLoader != null) {
- Thread.currentThread().setContextClassLoader(oldCL);
- }
- } catch (SAXException saxe) {
- saxe.printStackTrace();
- handleException(saxe);
- } catch (IOException ioe) {
- ioe.printStackTrace();
- handleException(ioe);
- } finally {
- iterator = objects.iterator();
+ /**
+ * Sets the exception listener.
+ *
+ * @param listener an exception listener
+ */
+ public void setExceptionListener(ExceptionListener listener) {
+ if (listener != null) {
+ this.listener = listener;
}
}
+
+ /**
+ * Sets the owner of this decoder.
+ *
+ * @param owner the owner of this decoder
+ */
+ public void setOwner(Object owner) {
+ this.owner = owner;
+ }
}
+
+
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_reflect_MethodPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_reflect_MethodPersistenceDelegate.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_reflect_MethodPersistenceDelegate.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_reflect_MethodPersistenceDelegate.java Mon Jul 16 23:30:22 2007
@@ -32,7 +32,7 @@
assert oldInstance instanceof Method : oldInstance;
Method oldMethod = (Method) oldInstance;
Class<?> declClass = oldMethod.getDeclaringClass();
- return new Expression(oldMethod, declClass, "getDeclaredMethod", //$NON-NLS-1$
+ return new Expression(oldMethod, declClass, "getMethod", //$NON-NLS-1$
new Object[] { oldMethod.getName(), oldMethod.getParameterTypes() });
}
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventSetDescriptorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventSetDescriptorTest.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventSetDescriptorTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventSetDescriptorTest.java Mon Jul 16 23:30:22 2007
@@ -17,6 +17,7 @@
package org.apache.harmony.beans.tests.java.beans;
+import java.awt.event.ActionListener;
import java.beans.EventSetDescriptor;
import java.beans.IntrospectionException;
import java.beans.MethodDescriptor;
@@ -33,6 +34,8 @@
import org.apache.harmony.beans.tests.support.mock.MockFakeListener;
import org.apache.harmony.beans.tests.support.mock.MockPropertyChangeEvent;
import org.apache.harmony.beans.tests.support.mock.MockPropertyChangeListener;
+import org.apache.harmony.beans.tests.support.mock.MockPropertyChangeValidListener;
+
/**
* Unit test for EventSetDescriptor
@@ -86,6 +89,9 @@
assertEquals(listenerType, esd.getListenerType());
assertTrue(esd.isInDefaultEventSet());
assertFalse(esd.isUnicast());
+
+ esd = new EventSetDescriptor(AnObject.class, "something",
+ AnObjectListener.class, "aMethod");
}
public void testEventSetDescriptorClassStringClassString2()
@@ -479,6 +485,21 @@
} catch (IntrospectionException e) {
}
}
+
+ public void testEventSetDescriptorClassStringClassStringArrayStringString_listenerMethodNamesValid()
+ throws Exception {
+ Class<MockSourceClass> sourceClass = MockSourceClass.class;
+ String eventSetName = "MockPropertyChange";
+ Class<?> listenerType = MockPropertyChangeValidListener.class;
+ String[] listenerMethodNames = { "mockPropertyChange_Valid",
+ "mockPropertyChange2", };
+ String addMethod = "addMockPropertyChangeListener";
+ String removeMethod = "removeMockPropertyChangeListener";
+ EventSetDescriptor eventSetDescriptor = new EventSetDescriptor(
+ sourceClass, eventSetName, listenerType, listenerMethodNames,
+ addMethod, removeMethod);
+ assertEquals(2, eventSetDescriptor.getListenerMethods().length);
+ }
public void testEventSetDescriptorClassStringClassStringArrayStringString_listenerMethodNamesEmpty()
throws IntrospectionException {
@@ -1254,6 +1275,33 @@
}
}
+
+ //Regression Test
+ public void testConstructor_withLackRemoveActionBean() throws Exception {
+ try {
+ new EventSetDescriptor(LackRemoveActionBean.class, "action",
+ ActionListener.class, "actionPerformed");
+ fail("should throw IntrospectionException");
+ } catch (IntrospectionException e) {
+ // expected
+ }
+ }
+
+ public void testConstructor_withAnotherListener() throws Exception {
+ Method[] listenermethods = AnotherObjectListener.class
+ .getDeclaredMethods();
+
+ Method add = AnObject.class.getDeclaredMethod(
+ "addEventSetDescriptorTest$AnObjectListener",
+ AnObjectListener.class);
+ Method remove = AnObject.class.getDeclaredMethod(
+ "removeEventSetDescriptorTest$AnObjectListener",
+ AnObjectListener.class);
+
+ EventSetDescriptor esd = new EventSetDescriptor("something",
+ AnObjectListener.class, listenermethods, add, remove);
+ assertNotNull(esd);
+ }
protected String getUnQualifiedClassName(Class<?> classType) {
String qName = classType.getName();
@@ -1298,6 +1346,52 @@
public void removeMockFakeListener(MockFakeListener listener) {
}
+ }
+
+ public class LackRemoveActionBean {
+ public void addActionListener(ActionListener al) {
+ }
+ // No removeActionListener() method
+ }
+
+ private interface AnObjectListener {
+ public void aMethod( SomethingEvent s );
+ }
+
+ private static class AnObject {
+ public void addEventSetDescriptorTest$AnObjectListener( AnObjectListener l ) {}
+ public void removeEventSetDescriptorTest$AnObjectListener( AnObjectListener l ) {}
+ }
+
+ private static class SomethingEvent {
+
+ }
+
+ public static void main(String[] args) throws Exception {
+
+ try {
+ // No need to do anything clever, there's only one method and it's
+ // the one we want.
+ // Swap these two lines to make Harmony pass.
+ //Method[] listenermethods = AnObjectListener.class.getDeclaredMethods();
+ Method[] listenermethods = AnotherObjectListener.class.getDeclaredMethods();
+
+ Method add = AnObject.class.getDeclaredMethod( "addEventSetDescriptorTest3$AnObjectListener",
+ AnObjectListener.class );
+ Method remove = AnObject.class.getDeclaredMethod( "removeEventSetDescriptorTest3$AnObjectListener",
+ AnObjectListener.class );
+
+ EventSetDescriptor esd = new EventSetDescriptor("something",
+ AnObjectListener.class, listenermethods, add, remove);
+ System.out.println("Test passed.");
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.out.println("Test failed.");
+ }
+ }
+
+ private interface AnotherObjectListener {
+ public void anotherMethod(SomethingEvent s);
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java Mon Jul 16 23:30:22 2007
@@ -21,23 +21,22 @@
import java.beans.Expression;
import java.beans.PersistenceDelegate;
import java.beans.Statement;
-
-import java.util.Stack;
+import java.beans.XMLDecoder;
+import java.beans.XMLEncoder;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.EmptyStackException;
+import java.util.Stack;
import junit.framework.TestCase;
import org.apache.harmony.beans.tests.support.mock.MockFoo;
import org.apache.harmony.beans.tests.support.mock.MockFooStop;
-
-import java.beans.XMLEncoder;
-import java.beans.XMLDecoder;
-import java.io.ByteArrayOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.BufferedOutputStream;
-import java.io.IOException;
-import java.lang.reflect.Field;
/**
* Test java.beans.PersistenceDelegate
*/
@@ -251,6 +250,23 @@
assertEquals(value, field);
assertEquals(value.getName(), field.getName());
}
+
+ public void test_writeObject_java_lang_reflect_Method() throws SecurityException, NoSuchMethodException{
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+ Method method = Bar.class.getMethod("barTalk", (Class[])null);
+
+ encoder.writeObject(method);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ Method aMethod = (Method) decoder.readObject();
+ assertEquals(method, aMethod);
+ assertEquals(method.getName(), aMethod.getName());
+ assertEquals("barTalk", aMethod.getName());
+ }
// <--
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java Mon Jul 16 23:30:22 2007
@@ -1129,5 +1129,25 @@
public InvalidPropertyEditor2() {
}
}
+
+ //Regression Test
+
+ private class MockBean {
+ int a;
+ public int getA() {
+ return a;
+ }
+ public void setA(int a) {
+ this.a = a;
+ }
+ }
+
+ public void testHashCode() throws IntrospectionException,
+ SecurityException, NoSuchMethodException {
+ PropertyDescriptor pd1 = new PropertyDescriptor("a",MockBean.class);
+ PropertyDescriptor pd2 = new PropertyDescriptor("a",MockBean.class);
+ assertEquals(pd1, pd2);
+ assertEquals(pd1.hashCode(), pd2.hashCode());
+ }
}
Modified: harmony/enhanced/classlib/branches/java6/modules/logging/src/main/java/java/util/logging/LogManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/logging/src/main/java/java/util/logging/LogManager.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/logging/src/main/java/java/util/logging/LogManager.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/logging/src/main/java/java/util/logging/LogManager.java Mon Jul 16 23:30:22 2007
@@ -345,12 +345,18 @@
// find children
//TODO: performance can be improved here?
Collection<Logger> allLoggers = loggers.values();
- for (Logger child : allLoggers) {
+ for (final Logger child : allLoggers) {
Logger oldParent = child.getParent();
if (parent == oldParent
&& (name.length() == 0 || child.getName().startsWith(
name + '.'))) {
- child.setParent(logger);
+ final Logger thisLogger = logger;
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ child.setParent(thisLogger);
+ return null;
+ }
+ });
if (null != oldParent) {
//-- remove from old parent as the parent has been changed
oldParent.removeChild(child);
Modified: harmony/enhanced/classlib/branches/java6/modules/logging/src/main/java/java/util/logging/Logger.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/logging/src/main/java/java/util/logging/Logger.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/logging/src/main/java/java/util/logging/Logger.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/logging/src/main/java/java/util/logging/Logger.java Mon Jul 16 23:30:22 2007
@@ -1385,10 +1385,15 @@
handlerInited = false;
}
//init level here, but let handlers be for lazy loading
- String configedLevel = manager.getProperty(name+ ".level"); //$NON-NLS-1$
+ final String configedLevel = manager.getProperty(name+ ".level"); //$NON-NLS-1$
if (null != configedLevel) {
try {
- setLevel(Level.parse(configedLevel));
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ setLevel(Level.parse(configedLevel));
+ return null;
+ }
+ });
} catch (IllegalArgumentException e) {
//ignore
}
Modified: harmony/enhanced/classlib/branches/java6/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java Mon Jul 16 23:30:22 2007
@@ -76,9 +76,9 @@
* Reset the log manager.
*/
protected void tearDown() throws Exception {
- super.tearDown();
CallVerificationStack.getInstance().clear();
Locale.setDefault(oldLocale);
+ super.tearDown();
}
/**
@@ -3414,6 +3414,42 @@
} catch (MissingResourceException ex) {
// Expected exception is precisely a MissingResourceException
assertTrue(ex.getClass() == MissingResourceException.class);
+ }
+ }
+
+ /**
+ * @tests java.util.logging.Logger#logrb(Level, String, String, String,
+ * String, Object)
+ */
+ public void test_init_logger()
+ throws Exception {
+ Properties p = new Properties();
+ p.put("testGetLogger_Normal_ANewLogger2.level", "ALL");
+ LogManager.getLogManager().readConfiguration(
+ EnvironmentHelper.PropertiesToInputStream(p));
+
+ assertNull(LogManager.getLogManager().getLogger(
+ "testGetLogger_Normal_ANewLogger2"));
+ SecurityManager originalSecurityManager = System.getSecurityManager();
+ try {
+ System.setSecurityManager(new SecurityManager());
+ // should not throw expection
+ Logger logger = Logger.getLogger("testGetLogger_Normal_ANewLogger2");
+ // should thrpw exception
+ try{
+ logger.setLevel(Level.ALL);
+ fail("should throw SecurityException");
+ } catch (SecurityException e){
+ // expected
+ }
+ try{
+ logger.setParent(Logger.getLogger("root"));
+ fail("should throw SecurityException");
+ } catch (SecurityException e){
+ // expected
+ }
+ } finally {
+ System.setSecurityManager(originalSecurityManager);
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/java/security/PermissionCollection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/java/security/PermissionCollection.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/java/security/PermissionCollection.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/java/security/PermissionCollection.java Mon Jul 16 23:30:22 2007
@@ -122,8 +122,8 @@
StringBuffer result = new StringBuffer(totalLength).append(superStr)
.append(" ("); //$NON-NLS-1$
for (int i = 0; i < esize; i++) {
- result.append("\n ").append(elist.get(i).toString()); //$NON-NLS-1$
+ result.append("\n ").append(elist.get(i).toString()); //$NON-NLS-1$
}
- return result.append("\n)").toString(); //$NON-NLS-1$
+ return result.append("\n)\n").toString(); //$NON-NLS-1$
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/tests/api/java/security/PermissionCollectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/tests/api/java/security/PermissionCollectionTest.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/tests/api/java/security/PermissionCollectionTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/tests/api/java/security/PermissionCollectionTest.java Mon Jul 16 23:30:22 2007
@@ -222,6 +222,7 @@
"testing permissionCollection-isREadOnly");
assertNotNull("toString should have returned a string of elements",
permi.newPermissionCollection().toString());
+ assertTrue(permi.newPermissionCollection().toString().endsWith("\n"));
}
// FIXME move me to Support_Resources
Modified: harmony/enhanced/classlib/branches/java6/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/PermissionCollection_ImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/PermissionCollection_ImplTest.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/PermissionCollection_ImplTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/PermissionCollection_ImplTest.java Mon Jul 16 23:30:22 2007
@@ -64,12 +64,12 @@
// no elements
PermissionCollection pc = new RealPermissionCollection(null);
String superString = pc.getClass().getName() + "@" + Integer.toHexString(pc.hashCode());
- assertEquals("no elements", superString + " (\n)", pc.toString());
+ assertEquals("no elements", superString + " (\n)\n", pc.toString());
// several elements
pc = new RealPermissionCollection(Arrays.asList(new Object[]{"aaa", "bbb", "ccc"}));
superString = pc.getClass().getName() + "@" + Integer.toHexString(pc.hashCode());
- assertEquals("several elements", superString + " (\n aaa\n bbb\n ccc\n)", pc.toString());
+ assertEquals("several elements", superString + " (\n aaa\n bbb\n ccc\n)\n", pc.toString());
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/DriverManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/DriverManager.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/DriverManager.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/DriverManager.java Mon Jul 16 23:30:22 2007
@@ -56,7 +56,8 @@
private static final List<Driver> theDrivers = new ArrayList<Driver>(10);
// Permission for setting log
- private static final SQLPermission logPermission = new SQLPermission("setLog"); //$NON-NLS-1$
+ private static final SQLPermission logPermission = new SQLPermission(
+ "setLog"); //$NON-NLS-1$
/*
* Load drivers on initialization
@@ -122,7 +123,8 @@
ClassLoader callerClassLoader = VM.callerClassLoader();
if (!DriverManager.isClassFromClassLoader(driver, callerClassLoader)) {
- // sql.1=DriverManager: calling class not authorized to deregister JDBC driver
+ // sql.1=DriverManager: calling class not authorized to deregister
+ // JDBC driver
throw new SecurityException(Messages.getString("sql.1")); //$NON-NLS-1$
} // end if
synchronized (theDrivers) {
@@ -208,10 +210,10 @@
public static Connection getConnection(String url, String user,
String password) throws SQLException {
Properties theProperties = new Properties();
- if(null != user){
+ if (null != user) {
theProperties.setProperty("user", user); //$NON-NLS-1$
}
- if(null != password){
+ if (null != password) {
theProperties.setProperty("password", password); //$NON-NLS-1$
}
return getConnection(url, theProperties);
@@ -248,8 +250,8 @@
}
// If no drivers understand the URL, throw an SQLException
// sql.6=No suitable driver
- //SQLState: 08 - connection exception
- //001 - SQL-client unable to establish SQL-connection
+ // SQLState: 08 - connection exception
+ // 001 - SQL-client unable to establish SQL-connection
throw new SQLException(Messages.getString("sql.6"), "08001"); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -414,13 +416,13 @@
*/
private static boolean isClassFromClassLoader(Object theObject,
ClassLoader theClassLoader) {
-
+
if ((theObject == null) || (theClassLoader == null)) {
return false;
}
-
+
Class<?> objectClass = theObject.getClass();
-
+
try {
Class<?> checkClass = Class.forName(objectClass.getName(), true,
theClassLoader);
Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/SQLException.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/SQLException.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/SQLException.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/SQLException.java Mon Jul 16 23:30:22 2007
@@ -218,7 +218,7 @@
* @param ex
* the new SQLException to be added to the end of the chain
*/
- public void setNextException(SQLException ex) {
+ public void setNextException(SQLException ex) {
if (next != null) {
next.setNextException(ex);
} else {
Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Time.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Time.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Time.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Time.java Mon Jul 16 23:30:22 2007
@@ -204,18 +204,21 @@
}
int firstIndex = timeString.indexOf(':');
int secondIndex = timeString.indexOf(':', firstIndex + 1);
- // secondIndex == -1 means none or only one separator '-' has been found.
+ // secondIndex == -1 means none or only one separator '-' has been
+ // found.
// The string is separated into three parts by two separator characters,
// if the first or the third part is null string, we should throw
// IllegalArgumentException to follow RI
- if (secondIndex == -1|| firstIndex == 0 || secondIndex + 1 == timeString.length()) {
+ if (secondIndex == -1 || firstIndex == 0
+ || secondIndex + 1 == timeString.length()) {
throw new IllegalArgumentException();
}
// parse each part of the string
int hour = Integer.parseInt(timeString.substring(0, firstIndex));
- int minute = Integer.parseInt(timeString.substring(firstIndex + 1, secondIndex));
- int second = Integer.parseInt(timeString.substring(secondIndex + 1, timeString
- .length()));
+ int minute = Integer.parseInt(timeString.substring(firstIndex + 1,
+ secondIndex));
+ int second = Integer.parseInt(timeString.substring(secondIndex + 1,
+ timeString.length()));
return new Time(hour, minute, second);
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Timestamp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Timestamp.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Timestamp.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Timestamp.java Mon Jul 16 23:30:22 2007
@@ -318,7 +318,7 @@
decimalFormat.setMaximumIntegerDigits(9);
String theNanos = decimalFormat.format(nanos);
theNanos = stripTrailingZeros(theNanos);
-
+
String year = format((getYear() + 1900), 4);
String month = format((getMonth() + 1), 2);
String date = format(getDate(), 2);
@@ -336,11 +336,11 @@
private String format(int date, int digits) {
StringBuilder dateStringBuffer = new StringBuilder(String.valueOf(date));
while (dateStringBuffer.length() < digits) {
- dateStringBuffer = dateStringBuffer.insert(0,'0');
+ dateStringBuffer = dateStringBuffer.insert(0, '0');
}
return dateStringBuffer.toString();
}
-
+
/*
* Private method to strip trailing '0' characters from a string. @param
* inputString the starting string @return a string with the trailing zeros
@@ -439,7 +439,8 @@
// Require the next character to be a "."
if (s.charAt(position) != '.') {
// sql.4=Bad input string format: expected '.' not {0}
- throw new NumberFormatException(Messages.getString("sql.4", s.charAt(position))); //$NON-NLS-1$
+ throw new NumberFormatException(Messages.getString(
+ "sql.4", s.charAt(position))); //$NON-NLS-1$
}
// Get the length of the number string - need to account for the '.'
int nanoLength = s.length() - position - 1;
Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/RowSet.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/RowSet.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/RowSet.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/RowSet.java Mon Jul 16 23:30:22 2007
@@ -154,8 +154,8 @@
public int getMaxRows() throws SQLException;
/**
- * Gets the value of the password property for this RowSet. This property
- * is used when making a connection to the database and should be set before
+ * Gets the value of the password property for this RowSet. This property is
+ * used when making a connection to the database and should be set before
* invoking the <code>execute</code> method.
*
* @return a String containing the value of the password property.
@@ -187,8 +187,8 @@
/**
* Gets the custom mapping of SQL types for this RowSet, if any.
*
- * @return a Map holding the custom mappings of SQL types to Java classes for
- * this RowSet. By default, the Map is empty.
+ * @return a Map holding the custom mappings of SQL types to Java classes
+ * for this RowSet. By default, the Map is empty.
* @throws SQLException
* if an error occurs accessing the database.
*/
@@ -452,7 +452,8 @@
* @param theDate
* the Date to use
* @param theCalendar
- * the Calendar to use in converting the Date to an SQL DATE value
+ * the Calendar to use in converting the Date to an SQL DATE
+ * value
* @throws SQLException
* if an error occurs accessing the database.
*/
Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/BaseRowSet.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/BaseRowSet.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/BaseRowSet.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/BaseRowSet.java Mon Jul 16 23:30:22 2007
@@ -45,8 +45,8 @@
import javax.sql.rowset.serial.SerialRef;
public abstract class BaseRowSet implements Cloneable, Serializable {
- private static final long serialVersionUID = 4886719666485113312L ;
-
+ private static final long serialVersionUID = 4886719666485113312L;
+
public static final int UNICODE_STREAM_PARAM = 0;
public static final int BINARY_STREAM_PARAM = 1;
@@ -215,15 +215,15 @@
public void setType(int type) throws SQLException {
switch (type) {
- case ResultSet.TYPE_FORWARD_ONLY:
- case ResultSet.TYPE_SCROLL_INSENSITIVE:
- case ResultSet.TYPE_SCROLL_SENSITIVE: {
- this.rowSetType = type;
- return;
- }
- default: {
- throw new SQLException();
- }
+ case ResultSet.TYPE_FORWARD_ONLY:
+ case ResultSet.TYPE_SCROLL_INSENSITIVE:
+ case ResultSet.TYPE_SCROLL_SENSITIVE: {
+ this.rowSetType = type;
+ return;
+ }
+ default: {
+ throw new SQLException();
+ }
}
}
@@ -233,14 +233,14 @@
public void setConcurrency(int concurrency) throws SQLException {
switch (concurrency) {
- case ResultSet.CONCUR_READ_ONLY:
- case ResultSet.CONCUR_UPDATABLE: {
- this.concurrency = concurrency;
- return;
- }
- default: {
- throw new SQLException();
- }
+ case ResultSet.CONCUR_READ_ONLY:
+ case ResultSet.CONCUR_UPDATABLE: {
+ this.concurrency = concurrency;
+ return;
+ }
+ default: {
+ throw new SQLException();
+ }
}
}
@@ -262,17 +262,17 @@
public void setTransactionIsolation(int level) throws SQLException {
switch (level) {
- case Connection.TRANSACTION_NONE:
- case Connection.TRANSACTION_READ_UNCOMMITTED:
- case Connection.TRANSACTION_READ_COMMITTED:
- case Connection.TRANSACTION_REPEATABLE_READ:
- case Connection.TRANSACTION_SERIALIZABLE: {
- this.isolation = level;
- return;
- }
- default: {
- throw new SQLException();
- }
+ case Connection.TRANSACTION_NONE:
+ case Connection.TRANSACTION_READ_UNCOMMITTED:
+ case Connection.TRANSACTION_READ_COMMITTED:
+ case Connection.TRANSACTION_REPEATABLE_READ:
+ case Connection.TRANSACTION_SERIALIZABLE: {
+ this.isolation = level;
+ return;
+ }
+ default: {
+ throw new SQLException();
+ }
}
}
@@ -330,20 +330,20 @@
public void setFetchDirection(int direction) throws SQLException {
switch (direction) {
- case ResultSet.FETCH_REVERSE:
- case ResultSet.FETCH_UNKNOWN: {
- if (rowSetType == ResultSet.TYPE_FORWARD_ONLY) {
- throw new SQLException();
- }
- }
- case ResultSet.FETCH_FORWARD: {
- this.fetchDir = direction;
- return;
- }
- default: {
+ case ResultSet.FETCH_REVERSE:
+ case ResultSet.FETCH_UNKNOWN: {
+ if (rowSetType == ResultSet.TYPE_FORWARD_ONLY) {
throw new SQLException();
}
}
+ case ResultSet.FETCH_FORWARD: {
+ this.fetchDir = direction;
+ return;
+ }
+ default: {
+ throw new SQLException();
+ }
+ }
}
public int getFetchDirection() throws SQLException {
@@ -376,7 +376,8 @@
params.put(Integer.valueOf(parameterIndex - 1), value);
}
- public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
+ public void setNull(int parameterIndex, int sqlType, String typeName)
+ throws SQLException {
if (parameterIndex < 1) {
throw new SQLException();
}
@@ -459,7 +460,8 @@
params.put(Integer.valueOf(parameterIndex - 1), Double.valueOf(x));
}
- public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
+ public void setBigDecimal(int parameterIndex, BigDecimal x)
+ throws SQLException {
if (parameterIndex < 1) {
throw new SQLException();
}
@@ -509,7 +511,8 @@
params.put(Integer.valueOf(parameterIndex - 1), x);
}
- public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
+ public void setTimestamp(int parameterIndex, Timestamp x)
+ throws SQLException {
if (parameterIndex < 1) {
throw new SQLException();
}
@@ -579,8 +582,8 @@
params.put(Integer.valueOf(parameterIndex - 1), value);
}
- public void setObject(int parameterIndex, Object x, int targetSqlType, int scale)
- throws SQLException {
+ public void setObject(int parameterIndex, Object x, int targetSqlType,
+ int scale) throws SQLException {
if (parameterIndex < 1) {
throw new SQLException();
}
@@ -594,7 +597,8 @@
params.put(Integer.valueOf(parameterIndex - 1), value);
}
- public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
+ public void setObject(int parameterIndex, Object x, int targetSqlType)
+ throws SQLException {
if (parameterIndex < 1) {
throw new SQLException();
}
@@ -657,7 +661,8 @@
params.put(Integer.valueOf(parameterIndex - 1), new SerialArray(array));
}
- public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
+ public void setDate(int parameterIndex, Date x, Calendar cal)
+ throws SQLException {
if (parameterIndex < 1) {
throw new SQLException();
}
@@ -670,7 +675,8 @@
params.put(Integer.valueOf(parameterIndex - 1), value);
}
- public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
+ public void setTime(int parameterIndex, Time x, Calendar cal)
+ throws SQLException {
if (parameterIndex < 1) {
throw new SQLException();
}
@@ -683,7 +689,8 @@
params.put(Integer.valueOf(parameterIndex - 1), value);
}
- public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
+ public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
+ throws SQLException {
if (parameterIndex < 1) {
throw new SQLException();
}
Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/RowSetMetaDataImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/RowSetMetaDataImpl.java?view=diff&rev=556825&r1=556824&r2=556825
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/RowSetMetaDataImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/RowSetMetaDataImpl.java Mon Jul 16 23:30:22 2007
@@ -40,54 +40,54 @@
private static final int DEFAULT_COLUMN_COUNT = 5;
private static final long serialVersionUID = 6893806403181801867L;
-
+
private int colCount;
private ColInfo[] colInfo;
/**
- * The default constructor.
+ * The default constructor.
*/
public RowSetMetaDataImpl() {
// do nothing
}
-
+
private void checkNegativeValue(int value, String msg) throws SQLException {
if (value < 0) {
throw new SQLException(Messages.getString(msg));
}
}
-
+
private void checkColumnIndex(int columnIndex) throws SQLException {
if (null == colInfo || columnIndex < 1 || columnIndex >= colInfo.length) {
throw new SQLException(Messages
.getString("sql.27", columnIndex + 1)); //$NON-NLS-1$
}
- // lazy initialization
+ // lazy initialization
if (null == colInfo[columnIndex]) {
colInfo[columnIndex] = new ColInfo();
}
}
-
+
/**
* {@inheritDoc}
*
* @see javax.sql.RowSetMetaData#setColumnCount(int)
*/
- public void setColumnCount(int columnCount) throws SQLException {
+ public void setColumnCount(int columnCount) throws SQLException {
if (columnCount <= 0) {
throw new SQLException(Messages.getString("sql.26")); //$NON-NLS-1$
}
try {
if (columnCount + 1 > 0) {
- colInfo = new ColInfo[columnCount + 1];
+ colInfo = new ColInfo[columnCount + 1];
} else {
colInfo = new ColInfo[DEFAULT_COLUMN_COUNT];
}
} catch (OutOfMemoryError e) {
// For compatibility, use same default value as RI
colInfo = new ColInfo[DEFAULT_COLUMN_COUNT];
- }
+ }
colCount = columnCount;
}
@@ -170,7 +170,7 @@
public void setColumnDisplaySize(int columnIndex, int size)
throws SQLException {
checkNegativeValue(size, "sql.30"); //$NON-NLS-1$
-
+
checkColumnIndex(columnIndex);
colInfo[columnIndex].columnDisplaySize = size;
}
@@ -218,7 +218,7 @@
public void setPrecision(int columnIndex, int precision)
throws SQLException {
checkNegativeValue(precision, "sql.31"); //$NON-NLS-1$
-
+
checkColumnIndex(columnIndex);
colInfo[columnIndex].precision = precision;
}
@@ -230,7 +230,7 @@
*/
public void setScale(int columnIndex, int scale) throws SQLException {
checkNegativeValue(scale, "sql.32"); //$NON-NLS-1$
-
+
checkColumnIndex(columnIndex);
colInfo[columnIndex].scale = scale;
}
@@ -266,8 +266,8 @@
*/
public void setColumnType(int columnIndex, int SQLType) throws SQLException {
SqlUtil.validateType(SQLType);
-
- checkColumnIndex(columnIndex);
+
+ checkColumnIndex(columnIndex);
colInfo[columnIndex].colType = SQLType;
}
@@ -299,7 +299,7 @@
*/
public boolean isAutoIncrement(int columnIndex) throws SQLException {
checkColumnIndex(columnIndex);
- return colInfo[columnIndex].autoIncrement;
+ return colInfo[columnIndex].autoIncrement;
}
/**
@@ -468,24 +468,24 @@
*/
public boolean isWritable(int columnIndex) throws SQLException {
checkColumnIndex(columnIndex);
- return colInfo[columnIndex].writeable;
+ return colInfo[columnIndex].writeable;
}
/**
* {@inheritDoc}
*
* @see java.sql.ResultSetMetaData#isDefinitelyWritable(int)
- */
+ */
public boolean isDefinitelyWritable(int columnIndex) throws SQLException {
checkColumnIndex(columnIndex);
- return colInfo[columnIndex].definiteWritable;
+ return colInfo[columnIndex].definiteWritable;
}
/**
* {@inheritDoc}
*
* @see java.sql.ResultSetMetaData#getColumnClassName(int)
- */
+ */
public String getColumnClassName(int columnIndex) throws SQLException {
return SqlUtil.getClassNameByType(getColumnType(columnIndex));
}
@@ -494,13 +494,13 @@
* The inner class to store meta information of columns.
*/
private class ColInfo implements Serializable {
-
+
private static final long serialVersionUID = 5490834817919311283L;
public boolean autoIncrement;
public boolean caseSensitive;
-
+
public boolean currency;
public boolean signed;
@@ -510,7 +510,7 @@
public boolean writeable = true;
public boolean definiteWritable = true;
-
+
public String columnLabel;
public String columnName;
@@ -520,17 +520,17 @@
public String colTypeName;
public int colType;
-
+
public int nullable;
-
+
public int columnDisplaySize;
-
+
public int precision;
-
+
public int scale;
-
+
public String tableName = EMPTY_STRING;
-
+
public String catalogName = EMPTY_STRING;
}
|