Author: taylor
Date: Thu Jul 14 12:22:38 2005
New Revision: 219077
URL: http://svn.apache.org/viewcvs?rev=219077&view=rev
Log:
persistence-component resurrected in part
required for registry field conversions
Added:
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CSVtoCollectionFieldConversion.java
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CSVtoPortletModeFieldConversion.java
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CollectionDebugger.java
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/FieldConversionLog.java
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/LocaleFieldConversion.java
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/ObjectIDtoLongFieldConversion.java
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/ObjectIDtoStringFieldConversion.java
Added:
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CSVtoCollectionFieldConversion.java
URL:
http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CSVtoCollectionFieldConversion.java?rev=219077&view=auto
==============================================================================
---
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CSVtoCollectionFieldConversion.java
(added)
+++
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CSVtoCollectionFieldConversion.java
Thu Jul 14 12:22:38 2005
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2000-2004 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.jetspeed.util.ojb;
+
+import java.io.IOException;
+import java.io.StreamTokenizer;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ojb.broker.accesslayer.conversions.ConversionException;
+import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
+
+/**
+ * <p style="font-weight: bold">
+ * ObjectRelationalBridge field conversion.
+ * </p>
+ * Converts from a comma-delimited field to a <code>java.util.collection</code>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
+ */
+public class CSVtoCollectionFieldConversion implements FieldConversion
+{
+ private static final String DELIM = ",";
+ private static final String QUOTE = "\"";
+
+ private static final Log log =
LogFactory.getLog(CSVtoCollectionFieldConversion.class);
+
+ /**
+ * @see
org.apache.ojb.broker.accesslayer.conversions.FieldConversion#javaToSql(java.lang.Object)
+ * @task Fix JDK 1.3 complient problem described in the FIXME
+ */
+ public Object javaToSql(Object arg0) throws ConversionException
+ {
+ if (arg0 instanceof Collection)
+ {
+ Collection col = ((Collection) arg0);
+ if (col.size() == 0)
+ {
+ return "";
+ }
+
+ Iterator itr = col.iterator();
+ // Estimate that the average word is going to be 5 characters long
+ StringBuffer buffer = new StringBuffer((col.size() * 5));
+ while (itr.hasNext())
+ {
+ buffer.append(QUOTE);
+ String value = getNext(itr);
+
+ // FIXME: The following is not JDK1.3 complient. So I
implement a warning
+ // message as a workaround until this field conversion
is no longer
+ // need and delete, or the code is made JDK 1.3
complient. (Paul Spencer)
+
+ // buffer.append(value.replaceAll("\"","\\\\\""));
+ if(value != null && value.toString().indexOf("\"") >= 0)
+ {
+ // FieldConversionLog.LOG.error("The string '" + value +
+ // "' contains embeded '\"'. It will not be converted to a
CSV correctly.");
+ log.warn("In CSVtoCollectionFieldConversion() - The string
'" + value +
+ "' contains embeded '\"'. It will not be converted to
a CSV correctly.");
+ }
+ buffer.append(value);
+ // End of FIXME:
+ buffer.append(QUOTE);
+
+ if (itr.hasNext())
+ {
+ buffer.append(DELIM);
+ }
+ }
+
+ return buffer.toString();
+ }
+ return arg0;
+ }
+
+ /**
+ * @see
org.apache.ojb.broker.accesslayer.conversions.FieldConversion#sqlToJava(java.lang.Object)
+ */
+ public Object sqlToJava(Object arg0) throws ConversionException
+ {
+
+ if (arg0 instanceof String)
+ {
+ StringReader sr = new StringReader((String) arg0);
+ StreamTokenizer st = new StreamTokenizer(sr);
+ st.resetSyntax();
+ st.whitespaceChars(',', ',');
+ st.quoteChar('"');
+ st.eolIsSignificant(false);
+
+
+ ArrayList list = new ArrayList();
+ try
+ {
+ while (st.nextToken() != StreamTokenizer.TT_EOF)
+ {
+ list.add(createObject(st.sval));
+ log.debug("Parsed token value: "+st.sval);
+ }
+ }
+ catch (IOException e)
+ {
+ String message = "CSV parsing failed during field conversion.";
+ log.error(message, e);
+ throw new ConversionException("CSV parsing failed during field
conversion.", e);
+ }
+
+ return list;
+ }
+
+ return arg0;
+ }
+
+ /**
+ * Makes creation of objects created via csv fields extensible
+ * By default simply return the string value.
+ *
+ * @param name The string value
+ * @return The string value
+ */
+ protected Object createObject(String name)
+ {
+ return name;
+ }
+
+ /**
+ * Makes getting objects via csv fields extensible
+ * By default simply return the string value.
+ *
+ * @param name The string value
+ * @return The string value
+ */
+ protected String getNext(Iterator iterator)
+ {
+ return (String) iterator.next();
+ }
+
+}
Added:
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CSVtoPortletModeFieldConversion.java
URL:
http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CSVtoPortletModeFieldConversion.java?rev=219077&view=auto
==============================================================================
---
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CSVtoPortletModeFieldConversion.java
(added)
+++
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CSVtoPortletModeFieldConversion.java
Thu Jul 14 12:22:38 2005
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2000-2004 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.jetspeed.util.ojb;
+
+import java.util.Iterator;
+
+import javax.portlet.PortletMode;
+
+import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
+
+/**
+ * CSVtoPortletModeFieldConversion
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
+ * @version $Id: CSVtoPortletModeFieldConversion.java 185962 2004-03-08
01:03:33Z jford $
+ */
+public class CSVtoPortletModeFieldConversion extends
CSVtoCollectionFieldConversion implements FieldConversion
+{
+ /* (non-Javadoc)
+ * @see
org.apache.jetspeed.util.ojb.CSVtoCollectionFieldConversion#getNext(java.util.Iterator)
+ */
+ protected String getNext(Iterator iterator)
+ {
+ PortletMode mode = (PortletMode)iterator.next();
+ return mode.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.jetspeed.util.ojb.CSVtoCollectionFieldConversion#createObject(java.lang.String)
+ */
+ protected Object createObject(String name)
+ {
+ return new PortletMode(name);
+ }
+
+
+}
Added:
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CollectionDebugger.java
URL:
http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CollectionDebugger.java?rev=219077&view=auto
==============================================================================
---
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CollectionDebugger.java
(added)
+++
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/CollectionDebugger.java
Thu Jul 14 12:22:38 2005
@@ -0,0 +1,65 @@
+/**
+ * Created on Jan 22, 2004
+ *
+ *
+ * @author
+ */
+package org.apache.jetspeed.util.ojb;
+
+
+import org.apache.ojb.broker.PersistenceBroker;
+import org.apache.ojb.broker.accesslayer.QueryCustomizer;
+import org.apache.ojb.broker.metadata.CollectionDescriptor;
+
+import org.apache.ojb.broker.query.Query;
+import org.apache.ojb.broker.query.QueryByCriteria;
+
+
+/**
+ * <p>
+ * CollectionDebugger
+ * </p>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
+ * @version $Id: CollectionDebugger.java 185773 2004-02-24 00:31:46Z weaver $
+ *
+ */
+public class CollectionDebugger implements QueryCustomizer
+{
+
+ /**
+ * @see
org.apache.ojb.broker.accesslayer.QueryCustomizer#customizeQuery(java.lang.Object,
org.apache.ojb.broker.PersistenceBroker,
org.apache.ojb.broker.metadata.CollectionDescriptor,
org.apache.ojb.broker.query.QueryByCriteria)
+ */
+ public Query customizeQuery(Object arg0, PersistenceBroker pb,
CollectionDescriptor arg2, QueryByCriteria arg3)
+ {
+ return arg3;
+ }
+
+ /**
+ * @see
org.apache.ojb.broker.metadata.AttributeContainer#addAttribute(java.lang.String,
java.lang.String)
+ */
+ public void addAttribute(String arg0, String arg1)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @see
org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(java.lang.String,
java.lang.String)
+ */
+ public String getAttribute(String arg0, String arg1)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * @see
org.apache.ojb.broker.metadata.AttributeContainer#getAttribute(java.lang.String)
+ */
+ public String getAttribute(String arg0)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added:
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/FieldConversionLog.java
URL:
http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/FieldConversionLog.java?rev=219077&view=auto
==============================================================================
---
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/FieldConversionLog.java
(added)
+++
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/FieldConversionLog.java
Thu Jul 14 12:22:38 2005
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2000-2004 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.jetspeed.util.ojb;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Utility class that allows convenient access to commons=logging for OJB
+ * FiledConversions without having to define a
+ * <code>org.apache.commons.logging.Log</code> in each of conversion
+ * class.
+ *
+ [EMAIL PROTECTED] <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
+ */
+public abstract class FieldConversionLog
+{
+ /**
+ * There is only default ("package") access to this Log only as
+ * all OJB FieldConversions should be located here.
+ */
+ static final Log LOG = LogFactory.getLog("org.apache.jetspeed.util.ojb");
+}
Added:
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/LocaleFieldConversion.java
URL:
http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/LocaleFieldConversion.java?rev=219077&view=auto
==============================================================================
---
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/LocaleFieldConversion.java
(added)
+++
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/LocaleFieldConversion.java
Thu Jul 14 12:22:38 2005
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2000-2004 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.jetspeed.util.ojb;
+
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+import org.apache.jetspeed.util.JetspeedLocale;
+import org.apache.ojb.broker.accesslayer.conversions.ConversionException;
+import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
+
+/**
+ * <p style="font-weight: bold">
+ * ObjectRelationalBridge field conversion.
+ * </p>
+ * Helps transparently map Locale objects into a database table
+ * that contains country, langauge and variant field and vice versa.
+ *
+ * field should be tokenized with commas
+ */
+public class LocaleFieldConversion implements FieldConversion
+{
+ private static final String DELIM = ",";
+
+ /**
+ * @see
org.apache.ojb.broker.accesslayer.conversions.FieldConversion#javaToSql(java.lang.Object)
+ */
+ public Object javaToSql(Object arg0) throws ConversionException
+ {
+ if (arg0 instanceof Locale)
+ {
+
+ Locale locale = (Locale) arg0;
+ String country = locale.getCountry();
+ String language = locale.getLanguage();
+ String variant = locale.getVariant();
+ StringBuffer buffer = new StringBuffer(40);
+ if (language != null)
+ {
+ buffer.append(language);
+ }
+ buffer.append(DELIM);
+
+ if (country != null)
+ {
+ buffer.append(country);
+ }
+ buffer.append(DELIM);
+
+ if (variant != null)
+ {
+ buffer.append(variant);
+ }
+
+ return buffer.toString().trim();
+ }
+ else
+ {
+ return arg0;
+ }
+ }
+
+ /**
+ * @see
org.apache.ojb.broker.accesslayer.conversions.FieldConversion#sqlToJava(java.lang.Object)
+ */
+ public Object sqlToJava(Object arg0) throws ConversionException
+ {
+ if (arg0 instanceof String)
+ {
+
+ String localeString = (String) arg0;
+ StringTokenizer tokenizer = new StringTokenizer(localeString,
DELIM);
+
+
+ String language = tokenizer.nextToken().trim();
+ String country = null;
+ String variant = null;
+ if(tokenizer.hasMoreTokens())
+ {
+ country = tokenizer.nextToken().trim();
+ }
+
+ if(tokenizer.hasMoreTokens())
+ {
+ variant = tokenizer.nextToken().trim();
+ }
+
+
+ if (country != null && language != null && variant != null)
+ {
+ return new Locale (language, country, variant);
+ }
+ else if (country != null && language != null)
+ {
+ return new Locale(language, country);
+ }
+ else if (language != null)
+ {
+ return new Locale(language, ""); // JDK 1.3 compatibility
+ }
+ else
+ {
+ return JetspeedLocale.getDefaultLocale();
+ }
+ }
+ else
+ {
+ return arg0;
+ }
+
+ }
+
+}
Added:
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/ObjectIDtoLongFieldConversion.java
URL:
http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/ObjectIDtoLongFieldConversion.java?rev=219077&view=auto
==============================================================================
---
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/ObjectIDtoLongFieldConversion.java
(added)
+++
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/ObjectIDtoLongFieldConversion.java
Thu Jul 14 12:22:38 2005
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2000-2004 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.jetspeed.util.ojb;
+
+import org.apache.jetspeed.util.JetspeedObjectID;
+import org.apache.ojb.broker.accesslayer.conversions.ConversionException;
+import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
+
+/**
+ * <p style="font-weight: bold">
+ * ObjectRelationalBridge field conversion.
+ * </p>
+ *
+ * Converts between <code>long</code> and <code>ObjectID</code>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
+ */
+public class ObjectIDtoLongFieldConversion implements FieldConversion
+{
+
+ /**
+ * @see
org.apache.ojb.broker.accesslayer.conversions.FieldConversion#javaToSql(java.lang.Object)
+ */
+ public Object javaToSql(Object arg0) throws ConversionException
+ {
+ if (arg0 instanceof JetspeedObjectID)
+ {
+ JetspeedObjectID oid = (JetspeedObjectID) arg0;
+
+ return new Long(oid.longValue());
+ }
+ else
+ {
+ return arg0;
+ }
+
+ }
+
+ /**
+ * @see
org.apache.ojb.broker.accesslayer.conversions.FieldConversion#sqlToJava(java.lang.Object)
+ */
+ public Object sqlToJava(Object arg0) throws ConversionException
+ {
+ if (arg0 instanceof Number)
+ {
+
+ return new JetspeedObjectID(((Number)arg0).longValue());
+ }
+ else
+ {
+ return arg0;
+ }
+
+ }
+
+}
Added:
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/ObjectIDtoStringFieldConversion.java
URL:
http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/ObjectIDtoStringFieldConversion.java?rev=219077&view=auto
==============================================================================
---
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/ObjectIDtoStringFieldConversion.java
(added)
+++
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/util/ojb/ObjectIDtoStringFieldConversion.java
Thu Jul 14 12:22:38 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2000-2004 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.jetspeed.util.ojb;
+
+import org.apache.jetspeed.util.JetspeedObjectID;
+import org.apache.ojb.broker.accesslayer.conversions.ConversionException;
+import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
+
+/**
+ * <p style="font-weight: bold">
+ * ObjectRelationalBridge field conversion.
+ * </p>
+ *
+ * Converts between <code>long</code> and <code>ObjectID</code>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
+ */
+public class ObjectIDtoStringFieldConversion implements FieldConversion
+{
+
+ /**
+ * @see
org.apache.ojb.broker.accesslayer.conversions.FieldConversion#javaToSql(java.lang.Object)
+ */
+ public Object javaToSql(Object arg0) throws ConversionException
+ {
+ if (arg0 instanceof JetspeedObjectID)
+ {
+ JetspeedObjectID oid = (JetspeedObjectID) arg0;
+
+ return oid.toString();
+ }
+ else
+ {
+ return arg0;
+ }
+
+ }
+
+ /**
+ * @see
org.apache.ojb.broker.accesslayer.conversions.FieldConversion#sqlToJava(java.lang.Object)
+ */
+ public Object sqlToJava(Object arg0) throws ConversionException
+ {
+ if (arg0 instanceof String)
+ {
+ return JetspeedObjectID.createFromString((String)arg0);
+ }
+ else
+ {
+ return arg0;
+ }
+
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]