You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2011/06/09 14:27:41 UTC
svn commit: r1133825 - in /incubator/wookie/trunk: etc/ddl-schema/
modules/jcr/src/org/apache/wookie/beans/jcr/
modules/jcr/src/org/apache/wookie/beans/jcr/impl/ src/META-INF/
src/org/apache/wookie/beans/ src/org/apache/wookie/beans/jpa/
src/org/apache...
Author: scottbw
Date: Thu Jun 9 12:27:40 2011
New Revision: 1133825
URL: http://svn.apache.org/viewvc?rev=1133825&view=rev
Log:
Refactored the widget author information attributes into a new localized IAuthor interface to reflect the W3C spec (see WOOKIE-119). Existing methods for working with author information have been deprecated in IWidget - however the implementation provides a facade to support them. Implemented for both JPA and JCR backends.
Added:
incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/impl/AuthorImpl.java
incubator/wookie/trunk/src/org/apache/wookie/beans/IAuthor.java
incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/AuthorImpl.java
Modified:
incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml
incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/impl/WidgetImpl.java
incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/wookie-schema.cnd
incubator/wookie/trunk/src/META-INF/persistence.xml
incubator/wookie/trunk/src/org/apache/wookie/beans/IWidget.java
incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/JPAPersistenceManager.java
incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/WidgetImpl.java
Modified: incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml?rev=1133825&r1=1133824&r2=1133825&view=diff
==============================================================================
--- incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml (original)
+++ incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml Thu Jun 9 12:27:40 2011
@@ -29,9 +29,6 @@
<column name="width" type="INTEGER"/>
<column name="guid" required="true" size="255" type="VARCHAR"/>
<column name="update_location" type="LONGVARCHAR"/>
- <column name="widget_author" size="255" type="VARCHAR"/>
- <column name="widget_author_email" size="320" type="VARCHAR"/>
- <column name="widget_author_href" type="LONGVARCHAR"/>
<column name="widget_version" size="255" type="VARCHAR"/>
<column name="dir" size="255" type="VARCHAR"/>
<column name="lang" size="255" type="VARCHAR"/>
@@ -87,6 +84,23 @@
<index-column name="widget_id"/>
</index>
</table>
+
+ <table name="Author">
+ <column name="id" primaryKey="true" required="true" type="INTEGER"/>
+ <column name="jpa_version" type="INTEGER"/>
+ <column name="author" type="LONGVARCHAR"/>
+ <column name="email" type="LONGVARCHAR"/>
+ <column name="href" type="LONGVARCHAR"/>
+ <column name="lang" size="255" type="VARCHAR"/>
+ <column name="dir" size="255" type="VARCHAR"/>
+ <column name="widget_id" type="INTEGER"/>
+ <foreign-key foreignTable="Widget" name="FKAuthor1">
+ <reference foreign="id" local="widget_id"/>
+ </foreign-key>
+ <index name="IXAuthor1">
+ <index-column name="widget_id"/>
+ </index>
+ </table>
<table name="AccessRequest">
<column name="id" primaryKey="true" required="true" type="INTEGER"/>
Added: incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/impl/AuthorImpl.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/impl/AuthorImpl.java?rev=1133825&view=auto
==============================================================================
--- incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/impl/AuthorImpl.java (added)
+++ incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/impl/AuthorImpl.java Thu Jun 9 12:27:40 2011
@@ -0,0 +1,96 @@
+/*
+ * 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.wookie.beans.jcr.impl;
+
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
+import org.apache.wookie.beans.IAuthor;
+import org.apache.wookie.beans.jcr.IIdElement;
+
+/**
+ * JCR Implementation of Author bean
+ */
+@Node(jcrType="wookie:author", extend=LocalizedBeanImpl.class, discriminator=false)
+public class AuthorImpl extends LocalizedBeanImpl implements IAuthor, IIdElement{
+
+ @Field(id=true, jcrName="wookie:elementId")
+ private long elementId = -1;
+
+ @Field(jcrName="wookie:author")
+ private String author;
+
+ @Field(jcrName="wookie:email")
+ private String email;
+
+ @Field(jcrName="wookie:href")
+ private String href;
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.jcr.IIdElement#getElementId()
+ */
+ public long getElementId()
+ {
+ return elementId;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.jcr.IIdElement#setElementId(long)
+ */
+ public void setElementId(long elementId)
+ {
+ this.elementId = elementId;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IAuthor#getAuthor()
+ */
+ public String getAuthor() {
+ return this.author;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IAuthor#getEmail()
+ */
+ public String getEmail() {
+ return this.email;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IAuthor#getHref()
+ */
+ public String getHref() {
+ return this.href;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IAuthor#setAuthor(java.lang.String)
+ */
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IAuthor#setEmail(java.lang.String)
+ */
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IAuthor#setHref(java.lang.String)
+ */
+ public void setHref(String href) {
+ this.href = href;
+ }
+}
Modified: incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/impl/WidgetImpl.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/impl/WidgetImpl.java?rev=1133825&r1=1133824&r2=1133825&view=diff
==============================================================================
--- incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/impl/WidgetImpl.java (original)
+++ incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/impl/WidgetImpl.java Thu Jun 9 12:27:40 2011
@@ -20,6 +20,7 @@ import java.util.Collection;
import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
+import org.apache.wookie.beans.IAuthor;
import org.apache.wookie.beans.IDescription;
import org.apache.wookie.beans.IFeature;
import org.apache.wookie.beans.ILicense;
@@ -33,6 +34,7 @@ import org.apache.wookie.beans.jcr.IPath
import org.apache.wookie.beans.jcr.IUuidBean;
import org.apache.wookie.beans.jcr.IdCollection;
import org.apache.wookie.beans.jcr.JCRPersistenceManager;
+import org.apache.wookie.beans.util.PersistenceManagerFactory;
/**
* WidgetImpl - JCR OCM IWidget implementation.
@@ -68,15 +70,6 @@ public class WidgetImpl extends Localize
@Field(jcrName="wookie:guid")
private String guid;
- @Field(jcrName="wookie:widgetAuthor")
- private String widgetAuthor;
-
- @Field(jcrName="wookie:widgetAuthorEmail")
- private String widgetAuthorEmail;
-
- @Field(jcrName="wookie:widgetAuthorHref")
- private String widgetAuthorHref;
-
@Field(jcrName="wookie:widgetVersion")
private String version;
@@ -95,6 +88,9 @@ public class WidgetImpl extends Localize
@org.apache.jackrabbit.ocm.mapper.impl.annotation.Collection(jcrName="wookie:names", elementClassName=NameImpl.class)
private Collection<NameImpl> nameImpls;
+ @org.apache.jackrabbit.ocm.mapper.impl.annotation.Collection(jcrName="wookie:authors", elementClassName=NameImpl.class)
+ private Collection<AuthorImpl> authorImpls;
+
@org.apache.jackrabbit.ocm.mapper.impl.annotation.Collection(jcrName="wookie:descriptions", elementClassName=DescriptionImpl.class)
private Collection<DescriptionImpl> descriptionImpls;
@@ -362,6 +358,67 @@ public class WidgetImpl extends Localize
{
this.nameImpls = nameImpls;
}
+
+ public Collection<IAuthor> getAuthors()
+ {
+ if (authorImpls == null)
+ {
+ authorImpls = new ArrayList<AuthorImpl>();
+ }
+ return new IdCollection<AuthorImpl,IAuthor>(authorImpls);
+ }
+
+ public void setAuthors(Collection<IAuthor> authors)
+ {
+ getAuthors().clear();
+ if (authors != null)
+ {
+ for (IAuthor author : authors)
+ {
+ getAuthors().add((AuthorImpl)author);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IWidget#getAuthor()
+ */
+ public IAuthor getAuthor(){
+ if (getAuthors().size() == 0) return null;
+ return getAuthors().iterator().next();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IWidget#setAuthor(org.apache.wookie.beans.IAuthor)
+ */
+ public void setAuthor(IAuthor author) {
+ getAuthors().clear();
+ getAuthors().add(author);
+ }
+
+ public IAuthor getOrCreateAuthor(){
+ if(getAuthor() == null){
+ IAuthor author = PersistenceManagerFactory.getPersistenceManager().newInstance(IAuthor.class);
+ setAuthor(author);
+ }
+ return getAuthor();
+ }
+
+ /**
+ * Get author implementations collection.
+ */
+ public Collection<AuthorImpl> getAuthorImpls()
+ {
+ return authorImpls;
+ }
+
+ /**
+ * Set author implementations collection.
+ */
+ public void setAuthorImpls(Collection<AuthorImpl> authorImpls)
+ {
+ this.authorImpls = authorImpls;
+ }
/* (non-Javadoc)
* @see org.apache.wookie.beans.jcr.IPathBean#getNodePath()
@@ -534,7 +591,7 @@ public class WidgetImpl extends Localize
*/
public String getWidgetAuthor()
{
- return widgetAuthor;
+ return getOrCreateAuthor().getAuthor();
}
/* (non-Javadoc)
@@ -542,7 +599,7 @@ public class WidgetImpl extends Localize
*/
public void setWidgetAuthor(String widgetAuthor)
{
- this.widgetAuthor = widgetAuthor;
+ getOrCreateAuthor().setAuthor(widgetAuthor);
}
/* (non-Javadoc)
@@ -550,7 +607,7 @@ public class WidgetImpl extends Localize
*/
public String getWidgetAuthorEmail()
{
- return widgetAuthorEmail;
+ return getOrCreateAuthor().getEmail();
}
/* (non-Javadoc)
@@ -558,7 +615,7 @@ public class WidgetImpl extends Localize
*/
public void setWidgetAuthorEmail(String widgetAuthorEmail)
{
- this.widgetAuthorEmail = widgetAuthorEmail;
+ getOrCreateAuthor().setEmail(widgetAuthorEmail);
}
/* (non-Javadoc)
@@ -566,7 +623,7 @@ public class WidgetImpl extends Localize
*/
public String getWidgetAuthorHref()
{
- return widgetAuthorHref;
+ return getOrCreateAuthor().getHref();
}
/* (non-Javadoc)
@@ -574,7 +631,7 @@ public class WidgetImpl extends Localize
*/
public void setWidgetAuthorHref(String widgetAuthorHref)
{
- this.widgetAuthorHref = widgetAuthorHref;
+ getOrCreateAuthor().setHref(widgetAuthorHref);
}
/* (non-Javadoc)
@@ -739,7 +796,7 @@ public class WidgetImpl extends Localize
return this.defaultLocale;
}
- public voud setDefaultLocale(String locale){
+ public void setDefaultLocale(String locale){
this.defaultLocale = locale;
}
}
Modified: incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/wookie-schema.cnd
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/wookie-schema.cnd?rev=1133825&r1=1133824&r2=1133825&view=diff
==============================================================================
--- incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/wookie-schema.cnd (original)
+++ incubator/wookie/trunk/modules/jcr/src/org/apache/wookie/beans/jcr/wookie-schema.cnd Thu Jun 9 12:27:40 2011
@@ -38,6 +38,14 @@
- wookie:dir (string)
- wookie:lang (string)
+[wookie:author] > nt:base
+- wookie:elementId (long)
+- wookie:authorName (string)
+- wookie:email (string)
+- wookie:href (string)
+- wookie:dir (string)
+- wookie:lang (string)
+
[wookie:description] > nt:base
- wookie:elementId (long)
- wookie:content (string)
Modified: incubator/wookie/trunk/src/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/META-INF/persistence.xml?rev=1133825&r1=1133824&r2=1133825&view=diff
==============================================================================
--- incubator/wookie/trunk/src/META-INF/persistence.xml (original)
+++ incubator/wookie/trunk/src/META-INF/persistence.xml Thu Jun 9 12:27:40 2011
@@ -27,6 +27,7 @@
<class>org.apache.wookie.beans.jpa.impl.LicenseImpl</class>
<class>org.apache.wookie.beans.jpa.impl.LocalizedBeanImpl</class>
<class>org.apache.wookie.beans.jpa.impl.NameImpl</class>
+ <class>org.apache.wookie.beans.jpa.impl.AuthorImpl</class>
<class>org.apache.wookie.beans.jpa.impl.ParamImpl</class>
<class>org.apache.wookie.beans.jpa.impl.ParticipantImpl</class>
<class>org.apache.wookie.beans.jpa.impl.PreferenceDefaultImpl</class>
Added: incubator/wookie/trunk/src/org/apache/wookie/beans/IAuthor.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/beans/IAuthor.java?rev=1133825&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/beans/IAuthor.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/beans/IAuthor.java Thu Jun 9 12:27:40 2011
@@ -0,0 +1,57 @@
+/*
+ * 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.wookie.beans;
+
+/**
+ * IAuthor - information about the author of the widget
+ */
+public interface IAuthor extends ILocalizedBean {
+
+ /**
+ * Get the details of the author, e.g. name or names of people and/or organisations
+ * @return the author details, or null if there are no author details
+ */
+ public String getAuthor();
+
+ /**
+ * Get the email address of the author
+ * @return the author email address, or null if there is no author email address
+ */
+ public String getEmail();
+
+ /**
+ * Get the URL of the author details, e.g. the author's blog or website address
+ * @return the author's URL, or null if there is no author URL
+ */
+ public String getHref();
+
+ /**
+ * Set the author details
+ * @param author tha author details to set
+ */
+ public void setAuthor(String author);
+
+ /**
+ * Set the author's email
+ * @param email the author email to set
+ */
+ public void setEmail(String email);
+
+ /**
+ * Set the author's Href
+ * @param href the author href to set
+ */
+ public void setHref(String href);
+
+}
Modified: incubator/wookie/trunk/src/org/apache/wookie/beans/IWidget.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/beans/IWidget.java?rev=1133825&r1=1133824&r2=1133825&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/beans/IWidget.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/beans/IWidget.java Thu Jun 9 12:27:40 2011
@@ -117,12 +117,25 @@ public interface IWidget extends ILocali
* @param guid widget GUID
*/
void setGuid(String guid);
+
+ /**
+ * Get the widget author
+ * @return widget author
+ */
+ IAuthor getAuthor();
+
+ /**
+ * Set the widget author
+ * @param author the author to set
+ */
+ void setAuthor(IAuthor author);
/**
* Get widget author.
*
* @return widget author
*/
+ @Deprecated
String getWidgetAuthor();
/**
@@ -130,6 +143,7 @@ public interface IWidget extends ILocali
*
* @param widgetAuthor widget author
*/
+ @Deprecated
void setWidgetAuthor(String widgetAuthor);
/**
@@ -137,6 +151,7 @@ public interface IWidget extends ILocali
*
* @return widget author email
*/
+ @Deprecated
String getWidgetAuthorEmail();
/**
@@ -144,6 +159,7 @@ public interface IWidget extends ILocali
*
* @param widgetAuthorEmail widget author email
*/
+ @Deprecated
void setWidgetAuthorEmail(String widgetAuthorEmail);
/**
@@ -151,6 +167,7 @@ public interface IWidget extends ILocali
*
* @return widget author href
*/
+ @Deprecated
String getWidgetAuthorHref();
/**
@@ -158,6 +175,7 @@ public interface IWidget extends ILocali
*
* @param widgetAuthorHref widget author href
*/
+ @Deprecated
void setWidgetAuthorHref(String widgetAuthorHref);
/**
@@ -324,6 +342,7 @@ public interface IWidget extends ILocali
*/
public static class Utilities
{
+
/**
* Get widget title for locale.
*
Modified: incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/JPAPersistenceManager.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/JPAPersistenceManager.java?rev=1133825&r1=1133824&r2=1133825&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/JPAPersistenceManager.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/JPAPersistenceManager.java Thu Jun 9 12:27:40 2011
@@ -49,6 +49,7 @@ import org.apache.openjpa.persistence.Qu
import org.apache.openjpa.persistence.StoreCache;
import org.apache.wookie.beans.IAccessRequest;
import org.apache.wookie.beans.IApiKey;
+import org.apache.wookie.beans.IAuthor;
import org.apache.wookie.beans.IBean;
import org.apache.wookie.beans.IDescription;
import org.apache.wookie.beans.IFeature;
@@ -70,6 +71,7 @@ import org.apache.wookie.beans.IWidgetSe
import org.apache.wookie.beans.IWidgetType;
import org.apache.wookie.beans.jpa.impl.AccessRequestImpl;
import org.apache.wookie.beans.jpa.impl.ApiKeyImpl;
+import org.apache.wookie.beans.jpa.impl.AuthorImpl;
import org.apache.wookie.beans.jpa.impl.DescriptionImpl;
import org.apache.wookie.beans.jpa.impl.FeatureImpl;
import org.apache.wookie.beans.jpa.impl.LicenseImpl;
@@ -121,6 +123,7 @@ public class JPAPersistenceManager imple
INTERFACE_TO_CLASS_MAP.put(IFeature.class, FeatureImpl.class);
INTERFACE_TO_CLASS_MAP.put(ILicense.class, LicenseImpl.class);
INTERFACE_TO_CLASS_MAP.put(IName.class, NameImpl.class);
+ INTERFACE_TO_CLASS_MAP.put(IAuthor.class, AuthorImpl.class);
INTERFACE_TO_CLASS_MAP.put(IParam.class, ParamImpl.class);
INTERFACE_TO_CLASS_MAP.put(IParticipant.class, ParticipantImpl.class);
INTERFACE_TO_CLASS_MAP.put(IPreference.class, PreferenceImpl.class);
Added: incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/AuthorImpl.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/AuthorImpl.java?rev=1133825&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/AuthorImpl.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/AuthorImpl.java Thu Jun 9 12:27:40 2011
@@ -0,0 +1,115 @@
+/*
+ * 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.wookie.beans.jpa.impl;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+import javax.persistence.Version;
+
+import org.apache.wookie.beans.IAuthor;
+import org.apache.wookie.beans.jpa.IInverseRelationship;
+
+/**
+ * AuthorImpl - JPA IAuthor implementation.
+ */
+@Entity(name="Author")
+@Table(name="Author")
+public class AuthorImpl extends LocalizedBeanImpl implements IAuthor, IInverseRelationship<WidgetImpl>
+{
+ @Id
+ @GeneratedValue(strategy=GenerationType.AUTO)
+ @Column(name="id", nullable=false)
+ @SuppressWarnings("unused")
+ private int id;
+
+ @Version
+ @Column(name="jpa_version")
+ @SuppressWarnings("unused")
+ private int jpaVersion;
+
+ @Basic
+ @Column(name="author")
+ private String author;
+
+ @Basic
+ @Column(name="email")
+ private String email;
+
+ @Basic
+ @Column(name="href")
+ private String href;
+
+ @ManyToOne(fetch=FetchType.LAZY)
+ @JoinColumn(name="widget_id", referencedColumnName="id")
+ @SuppressWarnings("unused")
+ private WidgetImpl widget;
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IAuthor#getAuthor()
+ */
+ public String getAuthor() {
+ return this.author;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IAuthor#getEmail()
+ */
+ public String getEmail() {
+ return this.email;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IAuthor#getHref()
+ */
+ public String getHref() {
+ return this.href;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IAuthor#setAuthor(java.lang.String)
+ */
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IAuthor#setEmail(java.lang.String)
+ */
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IAuthor#setHref(java.lang.String)
+ */
+ public void setHref(String href) {
+ this.href = href;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.jpa.IInverseRelationship#updateInverseRelationship(java.lang.Object)
+ */
+ public void updateInverseRelationship(WidgetImpl owningObject) {
+ widget = owningObject;
+ }
+}
Modified: incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/WidgetImpl.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/WidgetImpl.java?rev=1133825&r1=1133824&r2=1133825&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/WidgetImpl.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/WidgetImpl.java Thu Jun 9 12:27:40 2011
@@ -33,6 +33,7 @@ import javax.persistence.Version;
import org.apache.openjpa.persistence.ElementDependent;
+import org.apache.wookie.beans.IAuthor;
import org.apache.wookie.beans.IDescription;
import org.apache.wookie.beans.IFeature;
import org.apache.wookie.beans.ILicense;
@@ -43,6 +44,7 @@ import org.apache.wookie.beans.IWidget;
import org.apache.wookie.beans.IWidgetIcon;
import org.apache.wookie.beans.IWidgetType;
import org.apache.wookie.beans.jpa.InverseRelationshipCollection;
+import org.apache.wookie.beans.util.PersistenceManagerFactory;
/**
* WidgetImpl - JPA IWidget implementation.
@@ -94,18 +96,6 @@ public class WidgetImpl extends Localize
@Basic
@Column(name="default_locale")
private String defaultLocale;
-
- @Basic
- @Column(name="widget_author")
- private String widgetAuthor;
-
- @Basic
- @Column(name="widget_author_email")
- private String widgetAuthorEmail;
-
- @Basic
- @Column(name="widget_author_href")
- private String widgetAuthorHref;
@Basic
@Column(name="widget_version")
@@ -126,6 +116,10 @@ public class WidgetImpl extends Localize
@OneToMany(mappedBy="widget", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
@ElementDependent
private Collection<NameImpl> names;
+
+ @OneToMany(mappedBy="widget", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
+ @ElementDependent
+ private Collection<AuthorImpl> authors;
@OneToMany(mappedBy="widget", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
@ElementDependent
@@ -302,6 +296,44 @@ public class WidgetImpl extends Localize
}
/* (non-Javadoc)
+ * @see org.apache.wookie.beans.IWidget#getAuthor()
+ */
+ public IAuthor getAuthor() {
+ if (getAuthors().size() != 0)
+ return (IAuthor) getAuthors().iterator().next();
+ return null;
+ }
+
+ public Collection<IAuthor> getAuthors(){
+ if (authors == null)
+ {
+ authors = new ArrayList<AuthorImpl>();
+ }
+ return new InverseRelationshipCollection<WidgetImpl,AuthorImpl,IAuthor>(this, authors);
+ }
+
+ /**
+ * Utility method used to support legacy API calls, returns an IAuthor instance - whether pre-existing or newly
+ * created
+ * @return an IAuthor instance
+ */
+ private IAuthor getOrCreateAuthor(){
+ if (getAuthor() == null){
+ IAuthor author = PersistenceManagerFactory.getPersistenceManager().newInstance(IAuthor.class);
+ this.setAuthor(author);
+ }
+ return getAuthor();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.wookie.beans.IWidget#setAuthor(org.apache.wookie.beans.IAuthor)
+ */
+ public void setAuthor(IAuthor author) {
+ getAuthors().clear();
+ authors.add((AuthorImpl) author);
+ }
+
+ /* (non-Javadoc)
* @see org.apache.wookie.beans.IWidget#getPreferenceDefaults()
*/
public Collection<IPreferenceDefault> getPreferenceDefaults()
@@ -376,7 +408,7 @@ public class WidgetImpl extends Localize
*/
public String getWidgetAuthor()
{
- return widgetAuthor;
+ return getOrCreateAuthor().getAuthor();
}
/* (non-Javadoc)
@@ -384,7 +416,7 @@ public class WidgetImpl extends Localize
*/
public void setWidgetAuthor(String widgetAuthor)
{
- this.widgetAuthor = widgetAuthor;
+ this.getOrCreateAuthor().setAuthor(widgetAuthor);
}
/* (non-Javadoc)
@@ -392,7 +424,7 @@ public class WidgetImpl extends Localize
*/
public String getWidgetAuthorEmail()
{
- return widgetAuthorEmail;
+ return getOrCreateAuthor().getEmail();
}
/* (non-Javadoc)
@@ -400,7 +432,7 @@ public class WidgetImpl extends Localize
*/
public void setWidgetAuthorEmail(String widgetAuthorEmail)
{
- this.widgetAuthorEmail = widgetAuthorEmail;
+ this.getOrCreateAuthor().setEmail(widgetAuthorEmail);
}
/* (non-Javadoc)
@@ -408,7 +440,7 @@ public class WidgetImpl extends Localize
*/
public String getWidgetAuthorHref()
{
- return widgetAuthorHref;
+ return getOrCreateAuthor().getHref();
}
/* (non-Javadoc)
@@ -416,7 +448,7 @@ public class WidgetImpl extends Localize
*/
public void setWidgetAuthorHref(String widgetAuthorHref)
{
- this.widgetAuthorHref = widgetAuthorHref;
+ this.getOrCreateAuthor().setHref(widgetAuthorHref);
}
/* (non-Javadoc)