You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by aw...@apache.org on 2006/07/19 17:24:31 UTC
svn commit: r423535 -
/incubator/adffaces/trunk/adf-faces/adf-faces-api/src/main/java/org/apache/myfaces/adf/change/ChangeManager.java
Author: awiner
Date: Wed Jul 19 10:24:31 2006
New Revision: 423535
URL: http://svn.apache.org/viewvc?rev=423535&view=rev
Log:
ADFFACES-69: Bug Fix on the Change Persistence Manager: ADDCHILDCOMPONENTCHANGE FOR IMAGE THROWS NPE
Modified:
incubator/adffaces/trunk/adf-faces/adf-faces-api/src/main/java/org/apache/myfaces/adf/change/ChangeManager.java
Modified: incubator/adffaces/trunk/adf-faces/adf-faces-api/src/main/java/org/apache/myfaces/adf/change/ChangeManager.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/adf-faces/adf-faces-api/src/main/java/org/apache/myfaces/adf/change/ChangeManager.java?rev=423535&r1=423534&r2=423535&view=diff
==============================================================================
--- incubator/adffaces/trunk/adf-faces/adf-faces-api/src/main/java/org/apache/myfaces/adf/change/ChangeManager.java (original)
+++ incubator/adffaces/trunk/adf-faces/adf-faces-api/src/main/java/org/apache/myfaces/adf/change/ChangeManager.java Wed Jul 19 10:24:31 2006
@@ -1,218 +1,223 @@
-/*
- * Copyright 2005,2006 The Apache Software Foundation.
- *
- * 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.
- */
-
-package org.apache.myfaces.adf.change;
-
-import java.util.HashMap;
-import java.util.Iterator;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-import org.apache.myfaces.adf.logging.ADFLogger;
-
-/**
- * The base class for all ChangeManagers.
- * A ChangeManager should manage accumulation of Changes and also
- * take care of their persistence.
- * @version $Name: $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/change/ChangeManager.java#0 $) $Date: 10-nov-2005.19:09:58 $
- * @author The Oracle ADF Faces Team
- */
-public abstract class ChangeManager
-{
- public static void registerDocumentFactory(
- String targetClassName,
- String converterClassName)
- {
- if ((targetClassName == null) || (targetClassName.length() == 0))
- throw new IllegalArgumentException("target class name must be provided");
-
- if ((converterClassName == null) || (converterClassName.length() == 0))
- throw new IllegalArgumentException("converter class name must be provided");
-
- synchronized (_CLASSNAME_TO_CONVERTER_NAME_MAP)
- {
- _CLASSNAME_TO_CONVERTER_NAME_MAP.put(targetClassName, converterClassName);
- }
- }
-
- /**
- * Use the conversion rules to attempt to retrieve the equivalent
- * document change for a ComponentChange
- * @param change to convert
- */
- protected static DocumentChange createDocumentChange(
- ComponentChange change)
- {
- Class changeClass = change.getClass();
-
- Object converterObject = null;
- DocumentChangeFactory converter = null;
-
- //=-=pu todo (as info from Lakshmi) Converter returns null for case of facets
- synchronized (_CLASS_TO_CONVERTER_MAP)
- {
- converterObject = _CLASS_TO_CONVERTER_MAP.get(changeClass);
- }
-
- if (converterObject != null)
- {
- converter = (DocumentChangeFactory)converterObject;
- }
- else
- {
- String converterName = null;
-
- synchronized (_CLASSNAME_TO_CONVERTER_NAME_MAP)
- {
- converterName = (String)
- _CLASSNAME_TO_CONVERTER_NAME_MAP.get(changeClass.getName());
- }
-
- if (converterName != null)
- {
- try
- {
- ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
-
- Class converterClass = contextClassLoader.loadClass(converterName);
-
- if (DocumentChangeFactory.class.isAssignableFrom(converterClass))
- {
- converter = (DocumentChangeFactory)converterClass.newInstance();
-
- synchronized (_CLASS_TO_CONVERTER_MAP)
- {
- converterObject = _CLASS_TO_CONVERTER_MAP.put(changeClass,
- converter);
- }
- }
- else
- {
- // log warning because class isn't correct type
- _LOG.warning("Conversion class:" + converterClass + " not of type " + DocumentChangeFactory.class); // NOTRANS
- }
- }
- catch (Throwable e)
- {
- _LOG.warning("Unable to instantiate converterClass:" + converterName, e); // NOTRANS
- }
-
- if (converterObject == null)
- {
- // this entry doesn't work, so remove it
- _CLASSNAME_TO_CONVERTER_NAME_MAP.remove(converterName);
-
- return null;
- }
- }
- }
-
- // return the converted object
- return converter.convert(change);
- }
-
-
-
- /**
- * Add a ComponentChange to this current request for a specified component.
- * @throws IllegalArgumentException if any of the supplied parameters were to
- * be null.
- */
- public abstract void addComponentChange(
- FacesContext facesContext,
- UIComponent uiComponent,
- ComponentChange change);
-
- /**
- * Add a DocumentChange to this current request for a specified component.
- * @throws IllegalArgumentException if any of the supplied parameters were to
- * be null.
- */
- public void addDocumentChange(
- FacesContext facesContext,
- UIComponent uiComponent,
- DocumentChange change)
- {
- if (facesContext == null || uiComponent == null || change == null)
- throw new IllegalArgumentException(
- "Cannot add a Change with either of facesContext, uiComponent or " +
- "Change being null.");
- }
-
- /**
- * Retrieve the ComponentChanges available for specified component on this
- * request.
- * @return An Iterator of ComponentChanges in the order in which they
- * are associated with the UIComponent.
- * Returns <code>null<code> if there are no such Changes
- */
- public abstract Iterator getComponentChanges(
- FacesContext facesContext,
- UIComponent uiComponent);
-
- /**
- * Retrieve the identifiers of all components on this request that have Changes
- * associated with them.
- * @return An Iterator that can be used to access the collection of component
- * identifiers. Returns null if there are no such components.
- */
- public abstract Iterator getComponentIdsWithChanges(
- FacesContext facesContext);
-
- private static class AttributeConverter extends DocumentChangeFactory
- {
- public DocumentChange convert(ComponentChange compChange)
- {
- if (compChange instanceof AttributeComponentChange)
- {
- AttributeComponentChange change = (AttributeComponentChange)compChange;
-
- Object value = change.getAttributeValue();
-
- // =-= bts TODO add registration of attribute converters
- if ((value == null) ||
- (value instanceof CharSequence) ||
- (value instanceof Number) ||
- (value instanceof Boolean))
- {
- String valueString = (value != null)
- ? value.toString()
- : null;
-
- return new AttributeDocumentChange(change.getAttributeName(),
- valueString);
- }
- }
-
- // no conversion possible
- return null;
- }
- }
-
- private static HashMap _CLASSNAME_TO_CONVERTER_NAME_MAP = new HashMap();
- private static HashMap _CLASS_TO_CONVERTER_MAP = new HashMap();
-
- static private final ADFLogger _LOG = ADFLogger.createADFLogger(ChangeManager.class);
-
- static
- {
- // register the attribute converter
- _CLASS_TO_CONVERTER_MAP.put(AttributeComponentChange.class,
- new AttributeConverter());
- }
-
+/*
+ * Copyright 2005,2006 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+package org.apache.myfaces.adf.change;
+
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.adf.logging.ADFLogger;
+
+/**
+ * The base class for all ChangeManagers.
+ * A ChangeManager should manage accumulation of Changes and also
+ * take care of their persistence.
+ * @version $Name: $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/change/ChangeManager.java#0 $) $Date: 10-nov-2005.19:09:58 $
+ * @author The Oracle ADF Faces Team
+ */
+public abstract class ChangeManager
+{
+ public static void registerDocumentFactory(
+ String targetClassName,
+ String converterClassName)
+ {
+ if ((targetClassName == null) || (targetClassName.length() == 0))
+ throw new IllegalArgumentException("target class name must be provided");
+
+ if ((converterClassName == null) || (converterClassName.length() == 0))
+ throw new IllegalArgumentException("converter class name must be provided");
+
+ synchronized (_CLASSNAME_TO_CONVERTER_NAME_MAP)
+ {
+ _CLASSNAME_TO_CONVERTER_NAME_MAP.put(targetClassName, converterClassName);
+ }
+ }
+
+ /**
+ * Use the conversion rules to attempt to retrieve the equivalent
+ * document change for a ComponentChange
+ * @param change to convert
+ */
+ protected static DocumentChange createDocumentChange(
+ ComponentChange change)
+ {
+ Class changeClass = change.getClass();
+
+ Object converterObject = null;
+ DocumentChangeFactory converter = null;
+
+ synchronized (_CLASS_TO_CONVERTER_MAP)
+ {
+ converterObject = _CLASS_TO_CONVERTER_MAP.get(changeClass);
+ }
+
+ if (converterObject != null)
+ {
+ converter = (DocumentChangeFactory)converterObject;
+ }
+ else
+ {
+ String converterName = null;
+
+ synchronized (_CLASSNAME_TO_CONVERTER_NAME_MAP)
+ {
+ converterName =
+ _CLASSNAME_TO_CONVERTER_NAME_MAP.get(changeClass.getName());
+ }
+
+ if (converterName != null)
+ {
+ try
+ {
+ ClassLoader contextClassLoader =
+ Thread.currentThread().getContextClassLoader();
+
+ Class converterClass = contextClassLoader.loadClass(converterName);
+ if (DocumentChangeFactory.class.isAssignableFrom(converterClass))
+ {
+ converter = (DocumentChangeFactory)converterClass.newInstance();
+
+ synchronized (_CLASS_TO_CONVERTER_MAP)
+ {
+ _CLASS_TO_CONVERTER_MAP.put(changeClass, converter);
+ }
+ }
+ else
+ {
+ // log warning because class isn't correct type
+ _LOG.warning("Conversion class:" + converterClass + " not of type " + DocumentChangeFactory.class); // NOTRANS
+ }
+ }
+ catch (Throwable e)
+ {
+ _LOG.warning("Unable to instantiate converterClass:" + converterName, e); // NOTRANS
+ }
+
+ // if the registered converter class name doesn't work remove
+ // it from _CLASSNAME_TO_CONVERT_NAME_MAP
+ if (converter == null)
+ {
+ // this entry doesn't work, so remove it
+ _CLASSNAME_TO_CONVERTER_NAME_MAP.remove(converterName);
+
+ return null;
+ }
+ }
+ }
+
+ // return the converted object
+ if (converter != null)
+ return converter.convert(change);
+
+ return null;
+ }
+
+
+
+ /**
+ * Add a ComponentChange to this current request for a specified component.
+ * @throws IllegalArgumentException if any of the supplied parameters were to
+ * be null.
+ */
+ public abstract void addComponentChange(
+ FacesContext facesContext,
+ UIComponent uiComponent,
+ ComponentChange change);
+
+ /**
+ * Add a DocumentChange to this current request for a specified component.
+ * @throws IllegalArgumentException if any of the supplied parameters were to
+ * be null.
+ */
+ public void addDocumentChange(
+ FacesContext facesContext,
+ UIComponent uiComponent,
+ DocumentChange change)
+ {
+ if (facesContext == null || uiComponent == null || change == null)
+ throw new IllegalArgumentException(
+ "Cannot add a Change with either of facesContext, uiComponent or " +
+ "Change being null.");
+ }
+
+ /**
+ * Retrieve the ComponentChanges available for specified component on this
+ * request.
+ * @return An Iterator of ComponentChanges in the order in which they
+ * are associated with the UIComponent.
+ * Returns <code>null<code> if there are no such Changes
+ */
+ public abstract Iterator getComponentChanges(
+ FacesContext facesContext,
+ UIComponent uiComponent);
+
+ /**
+ * Retrieve the identifiers of all components on this request that have Changes
+ * associated with them.
+ * @return An Iterator that can be used to access the collection of component
+ * identifiers. Returns null if there are no such components.
+ */
+ public abstract Iterator getComponentIdsWithChanges(
+ FacesContext facesContext);
+
+ private static class AttributeConverter extends DocumentChangeFactory
+ {
+ public DocumentChange convert(ComponentChange compChange)
+ {
+ if (compChange instanceof AttributeComponentChange)
+ {
+ AttributeComponentChange change = (AttributeComponentChange)compChange;
+
+ Object value = change.getAttributeValue();
+
+ // =-= bts TODO add registration of attribute converters
+ if ((value == null) ||
+ (value instanceof CharSequence) ||
+ (value instanceof Number) ||
+ (value instanceof Boolean))
+ {
+ String valueString = (value != null)
+ ? value.toString()
+ : null;
+
+ return new AttributeDocumentChange(change.getAttributeName(),
+ valueString);
+ }
+ }
+
+ // no conversion possible
+ return null;
+ }
+ }
+
+ private static HashMap<String, String> _CLASSNAME_TO_CONVERTER_NAME_MAP =
+ new HashMap<String, String>();
+ private static HashMap _CLASS_TO_CONVERTER_MAP = new HashMap();
+
+ static private final ADFLogger _LOG =
+ ADFLogger.createADFLogger(ChangeManager.class);
+
+ static
+ {
+ // register the attribute converter
+ _CLASS_TO_CONVERTER_MAP.put(AttributeComponentChange.class,
+ new AttributeConverter());
+ }
+
}