You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2011/09/20 17:57:20 UTC
svn commit: r1173209 [34/49] - in /abdera/abdera2: ./ .settings/ activities/
activities/src/ activities/src/main/ activities/src/main/java/
activities/src/main/java/org/ activities/src/main/java/org/apache/
activities/src/main/java/org/apache/abdera2/ ...
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssSource.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssSource.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssSource.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssSource.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,406 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.rss;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.common.selector.Selector;
+import org.apache.abdera2.model.Category;
+import org.apache.abdera2.model.Collection;
+import org.apache.abdera2.model.DateTime;
+import org.apache.abdera2.model.Div;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.ExtensibleElementWrapper;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.model.Generator;
+import org.apache.abdera2.model.IRIElement;
+import org.apache.abdera2.model.Link;
+import org.apache.abdera2.model.Person;
+import org.apache.abdera2.model.Source;
+import org.apache.abdera2.model.Text;
+import org.apache.abdera2.model.Text.Type;
+
+@SuppressWarnings("unchecked")
+public class RssSource extends ExtensibleElementWrapper implements Source {
+
+ private Link self = null;
+
+ public RssSource(Element internal) {
+ super(internal);
+ self = new RssLink(internal);
+ }
+
+ public RssSource(Factory factory, QName qname) {
+ super(factory, qname);
+ self = new RssLink(factory, qname);
+ }
+
+ public <T extends Source> T addAuthor(Person person) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Person addAuthor(String name) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Person addAuthor(String name, String email, String iri) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public <T extends Source> T addCategory(Category category) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Category addCategory(String term) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Category addCategory(String scheme, String term, String label) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public <T extends Source> T addContributor(Person person) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Person addContributor(String name) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Person addContributor(String name, String email, String iri) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public <T extends Source> T addLink(Link link) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Link addLink(String href) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Link addLink(String href, String rel) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Link addLink(String href, String rel, String type, String title, String hreflang, long length) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Link getAlternateLink(String type, String hreflang) {
+ return getAlternateLink();
+ }
+
+ public IRI getAlternateLinkResolvedHref() {
+ Link link = getAlternateLink();
+ return (link != null) ? link.getResolvedHref() : null;
+ }
+
+ public IRI getAlternateLinkResolvedHref(String type, String hreflang) {
+ Link link = getAlternateLink();
+ return (link != null) ? link.getResolvedHref() : null;
+ }
+
+ public Person getAuthor() {
+ return null;
+ }
+
+ public List<Person> getAuthors() {
+ return Collections.EMPTY_LIST;
+ }
+
+ public List<Category> getCategories() {
+ return Collections.EMPTY_LIST;
+ }
+
+ public List<Category> getCategories(String scheme) {
+ return Collections.EMPTY_LIST;
+ }
+
+ public Collection getCollection() {
+ return null;
+ }
+
+ public List<Person> getContributors() {
+ return Collections.EMPTY_LIST;
+ }
+
+ public Generator getGenerator() {
+ return null;
+ }
+
+ public IRI getIcon() {
+ return null;
+ }
+
+ public IRIElement getIconElement() {
+ return null;
+ }
+
+ public IRI getId() {
+ return null;
+ }
+
+ public IRIElement getIdElement() {
+ return null;
+ }
+
+ public Link getLink(String rel) {
+ return null;
+ }
+
+ public IRI getLinkResolvedHref(String rel) {
+ return null;
+ }
+
+ public List<Link> getLinks() {
+ return Collections.EMPTY_LIST;
+ }
+
+ public List<Link> getLinks(String rel) {
+ return Collections.EMPTY_LIST;
+ }
+
+ public List<Link> getLinks(String... rel) {
+ return Collections.EMPTY_LIST;
+ }
+
+ public IRI getLogo() {
+ return null;
+ }
+
+ public IRIElement getLogoElement() {
+ return null;
+ }
+
+ public String getRights() {
+ return null;
+ }
+
+ public Text getRightsElement() {
+ return null;
+ }
+
+ public Type getRightsType() {
+ return null;
+ }
+
+ public Link getSelfLink() {
+ return getAlternateLink();
+ }
+
+ public IRI getSelfLinkResolvedHref() {
+ Link link = getSelfLink();
+ return (link != null) ? link.getResolvedHref() : null;
+ }
+
+ public String getSubtitle() {
+ return null;
+ }
+
+ public Text getSubtitleElement() {
+ return null;
+ }
+
+ public Type getSubtitleType() {
+ return null;
+ }
+
+ public String getTitle() {
+ return getText();
+ }
+
+ public Text getTitleElement() {
+ return null;
+ }
+
+ public Type getTitleType() {
+ return Type.HTML;
+ }
+
+ public Date getUpdated() {
+ return null;
+ }
+
+ public DateTime getUpdatedElement() {
+ return null;
+ }
+
+ public String getUpdatedString() {
+ return null;
+ }
+
+ public IRIElement newId() {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public <T extends Source> T setCollection(Collection collection) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public <T extends Source> T setGenerator(Generator generator) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Generator setGenerator(String iri, String version, String value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public IRIElement setIcon(String iri) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public <T extends Source> T setIconElement(IRIElement iri) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public IRIElement setId(String id) {
+ return null;
+ }
+
+ public IRIElement setId(String id, boolean normalize) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public <T extends Source> T setIdElement(IRIElement id) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public IRIElement setLogo(String iri) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public <T extends Source> T setLogoElement(IRIElement iri) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setRights(String value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setRights(String value, Type type) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setRights(Div value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setRightsAsHtml(String value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setRightsAsXhtml(String value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public <T extends Source> T setRightsElement(Text text) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setSubtitle(String value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setSubtitle(String value, Type type) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setSubtitle(Div value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setSubtitleAsHtml(String value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setSubtitleAsXhtml(String value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public <T extends Source> T setSubtitleElement(Text text) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setTitle(String value, Type type) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setTitle(Div value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setTitleAsHtml(String value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setTitleAsXhtml(String value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public <T extends Source> T setTitleElement(Text text) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public DateTime setUpdated(Date value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public DateTime setUpdated(String value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public <T extends Source> T setUpdatedElement(DateTime dateTime) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setTitle(String value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Link getAlternateLink() {
+ return self;
+ }
+
+ public Feed getAsFeed() {
+ throw new UnsupportedOperationException("Converting to feed is not supported");
+ }
+
+ public List<Person> getAuthors(Selector selector) {
+ return Collections.EMPTY_LIST;
+ }
+
+ public List<Category> getCategories(Selector selector) {
+ return Collections.EMPTY_LIST;
+ }
+
+ public List<Person> getContributors(Selector selector) {
+ return Collections.EMPTY_LIST;
+ }
+
+ public List<Link> getLinks(Selector selector) {
+ return Collections.EMPTY_LIST;
+ }
+
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssSource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssText.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssText.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssText.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssText.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.rss;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Div;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.ElementWrapper;
+import org.apache.abdera2.model.Text;
+
+public class RssText extends ElementWrapper implements Text {
+
+ public RssText(Element internal) {
+ super(internal);
+ }
+
+ public RssText(Factory factory, QName qname) {
+ super(factory, qname);
+ }
+
+ public Type getTextType() {
+ return Type.HTML;
+ }
+
+ public String getValue() {
+ return getText();
+ }
+
+ public Div getValueElement() {
+ return null;
+ }
+
+ public String getWrappedValue() {
+ return getValue();
+ }
+
+ public Text setTextType(Type type) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setValue(String value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setValueElement(Div value) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public Text setWrappedValue(String wrappedValue) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssText.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssTextInput.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssTextInput.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssTextInput.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssTextInput.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.rss;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.ExtensibleElementWrapper;
+import org.apache.abdera2.model.IRIElement;
+import org.apache.abdera2.model.Text;
+
+public class RssTextInput extends ExtensibleElementWrapper {
+
+ public RssTextInput(Element internal) {
+ super(internal);
+ }
+
+ public RssTextInput(Factory factory, QName qname) {
+ super(factory, qname);
+ }
+
+ public String getTitle() {
+ Text text = getExtension(RssConstants.QNAME_TITLE);
+ return (text != null) ? text.getValue() : null;
+ }
+
+ public String getDescription() {
+ Text text = getExtension(RssConstants.QNAME_DESCRIPTION);
+ return (text != null) ? text.getValue() : null;
+ }
+
+ public String getName() {
+ Element el = getExtension(RssConstants.QNAME_NAME);
+ return (el != null) ? el.getText() : null;
+ }
+
+ public IRI getLink() {
+ IRIElement iri = getExtension(RssConstants.QNAME_LINK);
+ return (iri != null) ? iri.getValue() : null;
+ }
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssTextInput.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssUriElement.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssUriElement.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssUriElement.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssUriElement.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.rss;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.ElementWrapper;
+import org.apache.abdera2.model.IRIElement;
+
+public class RssUriElement extends ElementWrapper implements IRIElement {
+
+ public RssUriElement(Element internal) {
+ super(internal);
+ }
+
+ public RssUriElement(Factory factory, QName qname) {
+ super(factory, qname);
+ }
+
+ public IRI getResolvedValue() {
+ return getValue();
+ }
+
+ public IRI getValue() {
+ return new IRI(getText());
+ }
+
+ public IRIElement setNormalizedValue(String iri) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+ public IRIElement setValue(String iri) {
+ throw new UnsupportedOperationException("Modifications are not allowed");
+ }
+
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/rss/RssUriElement.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/AbstractConventions.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/AbstractConventions.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/AbstractConventions.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/AbstractConventions.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Member;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.apache.abdera2.ext.serializer.annotation.Convention;
+
+public abstract class AbstractConventions implements Conventions, Cloneable, Serializable {
+
+ private static final long serialVersionUID = -6591462753642885957L;
+ private final Map<Class<? extends Annotation>, Pattern> conventions =
+ new HashMap<Class<? extends Annotation>, Pattern>();
+ private final boolean isCaseSensitive;
+
+ protected AbstractConventions() {
+ this(false);
+ }
+
+ protected AbstractConventions(boolean isCaseSensitive) {
+ this.isCaseSensitive = isCaseSensitive;
+ }
+
+ public Iterator<Class<? extends Annotation>> iterator() {
+ return conventions.keySet().iterator();
+ }
+
+ public void setConvention(String pattern, Class<? extends Annotation> annotationType) {
+ Pattern regex = isCaseSensitive ? Pattern.compile(pattern) : Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
+ conventions.put(annotationType, regex);
+ }
+
+ public void setConvention(Class<? extends Annotation> annotationType) {
+ Convention conv = annotationType.getAnnotation(Convention.class);
+ if (conv == null)
+ throw new IllegalArgumentException("No Convention Annotation [" + annotationType + "]");
+ setConvention(conv.value(), annotationType);
+ }
+
+ public Class<? extends Annotation> matchConvention(AccessibleObject accessor) {
+ return matchConvention(accessor, null);
+ }
+
+ public Class<? extends Annotation> matchConvention(AccessibleObject accessor, Class<? extends Annotation> expect) {
+ if (accessor == null)
+ return null;
+ String name = ((Member)accessor).getName();
+ for (Map.Entry<Class<? extends Annotation>, Pattern> entry : conventions.entrySet()) {
+ if (entry.getValue().matcher(name).matches() && (expect == null || expect == entry.getKey()))
+ return entry.getKey();
+ }
+ return null;
+ }
+
+ public boolean isMatch(AccessibleObject accessor, Class<? extends Annotation> expect) {
+ return matchConvention(accessor, expect) != null;
+ }
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((conventions == null) ? 0 : conventions.hashCode());
+ result = PRIME * result + (isCaseSensitive ? 1231 : 1237);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final AbstractConventions other = (AbstractConventions)obj;
+ if (conventions == null) {
+ if (other.conventions != null)
+ return false;
+ } else if (!conventions.equals(other.conventions))
+ return false;
+ if (isCaseSensitive != other.isCaseSensitive)
+ return false;
+ return true;
+ }
+
+ public Conventions clone() {
+ try {
+ return (Conventions)super.clone();
+ } catch (CloneNotSupportedException e) {
+ return copy();
+ }
+ }
+
+ protected Conventions copy() {
+ throw new SerializationException(new CloneNotSupportedException());
+ }
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/AbstractConventions.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/AbstractSerializationContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/AbstractSerializationContext.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/AbstractSerializationContext.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/AbstractSerializationContext.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.ext.serializer.impl.FOMSerializer;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.writer.StreamWriter;
+
+public abstract class AbstractSerializationContext implements SerializationContext {
+
+ private static final long serialVersionUID = 6002311037089864025L;
+ private final Abdera abdera;
+ private final StreamWriter streamWriter;
+ private final Map<Class<?>, Serializer> serializers = new HashMap<Class<?>, Serializer>();
+
+ protected AbstractSerializationContext(StreamWriter streamWriter) {
+ this(Abdera.getInstance(), streamWriter);
+ }
+
+ protected AbstractSerializationContext(Abdera abdera, StreamWriter streamWriter) {
+ this.abdera = abdera;
+ this.streamWriter = streamWriter;
+ setSerializer(Element.class, new FOMSerializer());
+ }
+
+ public StreamWriter getStreamWriter() {
+ return this.streamWriter;
+ }
+
+ public Abdera getAbdera() {
+ return abdera;
+ }
+
+ public Serializer getSerializer(ObjectContext objectContext) {
+ try {
+ Class<?> type = objectContext.getObjectType();
+ Serializer serializer = serializers.get(type);
+ if (serializer == null)
+ serializer = objectContext.getSerializer();
+ if (serializer == null) {
+ for (Annotation annotation : objectContext.getAnnotations()) {
+ serializer = serializers.get(annotation.annotationType());
+ if (serializer != null)
+ return serializer;
+ }
+ }
+ if (serializer == null && !type.isAnnotation()) {
+ for (Class<?> knownType : serializers.keySet()) {
+ if (!knownType.isAnnotation() && knownType.isAssignableFrom(type)) {
+ return serializers.get(knownType);
+ }
+ }
+ }
+ return serializer;
+ } catch (Throwable t) {
+ throw new SerializationException(t);
+ }
+ }
+
+ public boolean hasSerializer(ObjectContext objectContext) {
+ return getSerializer(objectContext) != null;
+ }
+
+ public boolean hasSerializer(Object object) {
+ return hasSerializer(new ObjectContext(object));
+ }
+
+ public boolean hasSerializer(Object object, Object parent, AccessibleObject accessor) {
+ return hasSerializer(new ObjectContext(object, parent, accessor));
+ }
+
+ public boolean hasSerializer(Class<?> type) {
+ if (serializers.containsKey(type))
+ return true;
+ if (!type.isAnnotation()) {
+ for (Class<?> t : serializers.keySet()) {
+ if (!t.isAnnotation() && t.isAssignableFrom(type))
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean hasSerializer(AccessibleObject accessor) {
+ Class<? extends Object> returnType = getReturnType(accessor);
+ org.apache.abdera2.ext.serializer.annotation.Serializer serializer =
+ accessor.getAnnotation(org.apache.abdera2.ext.serializer.annotation.Serializer.class);
+ if (serializer != null && hasSerializer(serializer.value()))
+ return true;
+ if (returnType != null && hasSerializer(returnType))
+ return true;
+ return false;
+ }
+
+ public void setSerializer(Class<?> type, Serializer Serializer) {
+ serializers.put(type, Serializer);
+ }
+
+ public void serialize(Object object) {
+ serialize(object, new ObjectContext(object));
+ }
+
+ public void serialize(Object object, ObjectContext objectContext) {
+ if (objectContext == null)
+ objectContext = new ObjectContext(object);
+ Serializer serializer = getSerializer(objectContext);
+ if (serializer != null)
+ serialize(object, objectContext, serializer);
+ else
+ throw new SerializationException("No Serializer available for " + objectContext.getObjectType());
+ }
+
+ public void serialize(Object object, Serializer serializer) {
+ serialize(object, new ObjectContext(object), serializer);
+ }
+
+ public void serialize(Object object, ObjectContext objectContext, Serializer serializer) {
+ if (objectContext == null)
+ objectContext = new ObjectContext(object);
+ Serializer overrideSerializer = getSerializer(objectContext);
+ if (overrideSerializer != null)
+ serializer = overrideSerializer;
+ if (serializer != null) {
+ serializer.serialize(object, objectContext, this);
+ } else {
+ throw new SerializationException("No Serializer available for " + objectContext.getObjectType());
+ }
+ }
+
+ public static Class<? extends Object> getReturnType(AccessibleObject accessor) {
+ if (accessor instanceof Field)
+ return ((Field)accessor).getType();
+ else if (accessor instanceof Method)
+ return ((Method)accessor).getReturnType();
+ else
+ return null;
+ }
+
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/AbstractSerializationContext.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/BaseSerializer.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/BaseSerializer.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/BaseSerializer.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/BaseSerializer.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,314 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.ext.serializer.annotation.Attribute;
+import org.apache.abdera2.ext.serializer.annotation.BaseURI;
+import org.apache.abdera2.ext.serializer.annotation.Extension;
+import org.apache.abdera2.ext.serializer.annotation.Language;
+import org.apache.abdera2.ext.serializer.annotation.Value;
+import org.apache.abdera2.ext.serializer.impl.ExtensionSerializer;
+import org.apache.abdera2.ext.serializer.impl.SimpleElementSerializer;
+import org.apache.abdera2.common.lang.Lang;
+import org.apache.abdera2.writer.StreamWriter;
+
+public abstract class BaseSerializer extends Serializer {
+
+ public static final String DEFAULT = "##default";
+
+ protected abstract void init(Object source,
+ ObjectContext objectContext,
+ SerializationContext context,
+ Conventions conventions);
+
+ protected abstract void finish(Object source,
+ ObjectContext objectContext,
+ SerializationContext context,
+ Conventions conventions);
+
+ protected void process(Object source,
+ ObjectContext objectContext,
+ SerializationContext context,
+ Conventions conventions) {
+ }
+
+ public void serialize(Object source, ObjectContext objectContext, SerializationContext context) {
+ Conventions conventions = ((ConventionSerializationContext)context).getConventions();
+ init(source, objectContext, context, conventions);
+ process(source, objectContext, context, conventions);
+ finish(source, objectContext, context, conventions);
+ }
+
+ protected void writeTextValue(Object source,
+ ObjectContext objectContext,
+ SerializationContext context,
+ Conventions conventions) {
+ AccessibleObject accessor = objectContext.getAccessor(Value.class, conventions);
+ Object value = null;
+ if (accessor != null) {
+ value = eval(accessor, source);
+ }
+ context.getStreamWriter().writeElementText(value != null ? toString(value) : toString(source));
+ }
+
+ protected void writeExtensions(Object source,
+ ObjectContext objectContext,
+ SerializationContext context,
+ Conventions conventions) {
+ AccessibleObject[] accessors = objectContext.getAccessors(Extension.class, conventions);
+ for (AccessibleObject accessor : accessors) {
+ Object value = eval(accessor, source);
+ ObjectContext valueContext = new ObjectContext(value, source, accessor);
+ Extension extension = valueContext.getAnnotation(Extension.class);
+ boolean simple = extension != null ? extension.simple() : false;
+ Serializer ser = context.getSerializer(valueContext);
+ if (ser == null) {
+ if (simple) {
+ QName qname = getQName(accessor);
+ ser = new SimpleElementSerializer(qname);
+ } else {
+ ser = context.getSerializer(valueContext);
+ if (ser == null) {
+ QName qname = getQName(accessor);
+ ser = new ExtensionSerializer(qname);
+ }
+ }
+ }
+ ser.serialize(value, valueContext, context);
+ }
+ }
+
+ protected void writeAttributes(Object source,
+ ObjectContext objectContext,
+ SerializationContext context,
+ Conventions conventions) {
+ writeCommon(source, objectContext, context, conventions);
+ StreamWriter sw = context.getStreamWriter();
+ AccessibleObject[] accessors = objectContext.getAccessors(Attribute.class, conventions);
+ for (AccessibleObject accessor : accessors) {
+ QName qname = getQName(accessor);
+ Object value = eval(accessor, source);
+ if (value != null)
+ sw.writeAttribute(qname, toString(value));
+ }
+ }
+
+ protected boolean writeElement(Class<? extends Annotation> annotation,
+ Serializer serializer,
+ Object source,
+ ObjectContext objectContext,
+ SerializationContext context,
+ Conventions conventions) {
+ AccessibleObject accessor = objectContext.getAccessor(annotation, conventions);
+ if (accessor != null) {
+ Object value = eval(accessor, source);
+ ObjectContext valueContext = new ObjectContext(value, source, accessor);
+ serializer.serialize(value, valueContext, context);
+ return true;
+ }
+ return false;
+ }
+
+ protected void writeElements(Class<? extends Annotation> annotation,
+ Serializer serializer,
+ Object source,
+ ObjectContext objectContext,
+ SerializationContext context,
+ Conventions conventions) {
+ AccessibleObject[] accessors = objectContext.getAccessors(annotation, conventions);
+ for (AccessibleObject accessor : accessors) {
+ if (accessor != null) {
+ Object value = eval(accessor, source);
+ Object[] values = toArray(value);
+ for (Object val : values) {
+ ObjectContext valueContext = new ObjectContext(val, source, accessor);
+ serializer.serialize(val, valueContext, context);
+ }
+ }
+ }
+ }
+
+ public static Object eval(AccessibleObject accessor, Object parent) {
+ try {
+ if (accessor instanceof Field)
+ return ((Field)accessor).get(parent);
+ else if (accessor instanceof Method)
+ return ((Method)accessor).invoke(parent, new Object[0]);
+ else
+ return null;
+ } catch (Throwable t) {
+ throw new SerializationException(t);
+ }
+ }
+
+ protected boolean hasAnnotation(AnnotatedElement item, Class<? extends Annotation> annotation) {
+ return item.isAnnotationPresent(annotation);
+ }
+
+ protected void writeElement(StreamWriter sw, QName qname, String value) {
+ sw.startElement(qname).writeElementText(value).endElement();
+ }
+
+ public static String toString(Object value) {
+ if (value == null)
+ return null;
+ Object[] values = toArray(value);
+ StringBuilder buf = new StringBuilder();
+ for (int n = 0; n < values.length; n++) {
+ if (n > 0)
+ buf.append(", ");
+ buf.append(values[n].toString());
+ }
+ return buf.toString();
+ }
+
+ public static Object[] toArray(Object value) {
+ if (value == null)
+ return new Object[0];
+ if (value.getClass().isArray()) {
+ return (Object[])value;
+ } else if (value instanceof Collection) {
+ return ((Collection<?>)value).toArray();
+ } else if (value instanceof Map) {
+ return ((Map<?,?>)value).values().toArray();
+ } else if (value instanceof Dictionary) {
+ List<Object> list = new ArrayList<Object>();
+ Enumeration<?> e = ((Dictionary<?,?>)value).elements();
+ while (e.hasMoreElements())
+ list.add(e.nextElement());
+ return list.toArray();
+ } else if (value instanceof Iterator) {
+ List<Object> list = new ArrayList<Object>();
+ Iterator<?> i = (Iterator<?>)value;
+ while (i.hasNext())
+ list.add(i.next());
+ return list.toArray();
+ } else if (value instanceof Enumeration) {
+ List<Object> list = new ArrayList<Object>();
+ Enumeration<?> e = (Enumeration<?>)value;
+ while (e.hasMoreElements())
+ list.add(e.nextElement());
+ return list.toArray();
+ } else if (value instanceof Iterable) {
+ List<Object> list = new ArrayList<Object>();
+ Iterable<?> v = (Iterable<?>)value;
+ Iterator<?> i = v.iterator();
+ while (i.hasNext())
+ list.add(i.next());
+ return list.toArray();
+ } else {
+ return new Object[] {value};
+ }
+ }
+
+ protected static boolean isUndefined(String value) {
+ return value == null || DEFAULT.equals(value);
+ }
+
+ protected static QName getQName(AccessibleObject accessor) {
+ Extension ext = accessor.getAnnotation(Extension.class);
+ if (ext != null)
+ return getQName(ext);
+ Attribute attr = accessor.getAnnotation(Attribute.class);
+ if (attr != null)
+ return getQName(attr);
+ return new QName(accessor instanceof Method ? ((Method)accessor).getName() : ((Field)accessor).getName());
+ }
+
+ protected static QName getQName(Extension extension) {
+ QName qname = null;
+ if (extension != null) {
+ if (isUndefined(extension.prefix()) && isUndefined(extension.ns()) && isUndefined(extension.name())) {
+ qname = new QName(extension.ns(), extension.name(), extension.prefix());
+ } else if (isUndefined(extension.prefix()) && !isUndefined(extension.ns())
+ && !isUndefined(extension.name())) {
+ qname = new QName(extension.ns(), extension.name());
+ } else if (!isUndefined(extension.name())) {
+ qname = new QName(extension.name());
+ }
+ }
+ return qname;
+ }
+
+ protected static QName getQName(Attribute attribute) {
+ QName qname = null;
+ if (attribute != null) {
+ if (isUndefined(attribute.prefix()) && isUndefined(attribute.ns()) && isUndefined(attribute.name())) {
+ qname = new QName(attribute.ns(), attribute.name(), attribute.prefix());
+ } else if (isUndefined(attribute.prefix()) && !isUndefined(attribute.ns())
+ && !isUndefined(attribute.name())) {
+ qname = new QName(attribute.ns(), attribute.name());
+ } else if (!isUndefined(attribute.name())) {
+ qname = new QName(attribute.name());
+ }
+ }
+ return qname;
+ }
+
+ protected void writeCommon(Object source,
+ ObjectContext objectContext,
+ SerializationContext context,
+ Conventions conventions) {
+ StreamWriter sw = context.getStreamWriter();
+ String lang = null;
+ AccessibleObject accessor = objectContext.getAccessor(Language.class, conventions);
+ if (accessor != null) {
+ Object value = eval(accessor, source);
+ if (value != null) {
+ if (value instanceof Lang) {
+ lang = value.toString();
+ } else {
+ lang = toString(value);
+ }
+ }
+ }
+ if (lang == null) {
+ Language _lang = objectContext.getAnnotation(Language.class);
+ if (_lang != null && !_lang.value().equals(DEFAULT)) {
+ lang = _lang.value();
+ }
+ }
+ if (lang != null)
+ sw.writeLanguage(lang);
+
+ String base = null;
+ accessor = objectContext.getAccessor(BaseURI.class, conventions);
+ if (accessor != null) {
+ Object value = eval(accessor, source);
+ if (value != null)
+ base = toString(value);
+ }
+ if (base != null)
+ sw.writeBase(base);
+ }
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/BaseSerializer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ConventionSerializationContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ConventionSerializationContext.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ConventionSerializationContext.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ConventionSerializationContext.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.writer.StreamWriter;
+
+public class ConventionSerializationContext extends DefaultSerializationContext {
+
+ private static final long serialVersionUID = 7504071837124132972L;
+
+ protected Conventions conventions;
+
+ public ConventionSerializationContext(StreamWriter streamWriter) {
+ this(Abdera.getInstance(), streamWriter);
+ }
+
+ public ConventionSerializationContext(Conventions conventions, StreamWriter streamWriter) {
+ this(null, conventions, streamWriter);
+ }
+
+ public ConventionSerializationContext(Abdera abdera, StreamWriter streamWriter) {
+ super(abdera, streamWriter);
+ this.conventions = new DefaultConventions();
+ initSerializers();
+ }
+
+ public ConventionSerializationContext(Abdera abdera, Conventions conventions, StreamWriter streamWriter) {
+ super(abdera, streamWriter);
+ this.conventions = conventions;
+ initSerializers();
+ }
+
+ public Conventions getConventions() {
+ return conventions;
+ }
+
+ public void setConventions(Conventions conventions) {
+ this.conventions = conventions;
+ }
+
+ public boolean hasSerializer(AccessibleObject accessor) {
+ boolean answer = super.hasSerializer(accessor);
+ if (answer)
+ return true;
+ Class<? extends Annotation> annotation = getConventions().matchConvention(accessor);
+ return annotation != null && hasSerializer(annotation);
+ }
+
+ private <T> void initSerializers() {
+ for (Class<? extends Annotation> type : conventions) {
+ org.apache.abdera2.ext.serializer.annotation.Serializer serializer =
+ type.getAnnotation(org.apache.abdera2.ext.serializer.annotation.Serializer.class);
+ if (serializer != null) {
+ try {
+ Serializer ser = serializer.value().newInstance();
+ this.setSerializer(type, ser);
+ } catch (Throwable t) {
+ throw new SerializationException(t);
+ }
+ }
+ }
+ }
+
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ConventionSerializationContext.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/Conventions.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/Conventions.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/Conventions.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/Conventions.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+
+public interface Conventions extends Serializable, Cloneable, Iterable<Class<? extends Annotation>> {
+
+ void setConvention(Class<? extends Annotation> annotationType);
+
+ void setConvention(String pattern, Class<? extends Annotation> annotationType);
+
+ Class<? extends Annotation> matchConvention(AccessibleObject accessor);
+
+ Class<? extends Annotation> matchConvention(AccessibleObject accessor, Class<? extends Annotation> expect);
+
+ boolean isMatch(AccessibleObject accessor, Class<? extends Annotation> expect);
+
+ Conventions clone();
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/Conventions.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/DefaultConventions.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/DefaultConventions.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/DefaultConventions.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/DefaultConventions.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer;
+
+import java.lang.annotation.Annotation;
+
+import org.apache.abdera2.ext.serializer.annotation.Accept;
+import org.apache.abdera2.ext.serializer.annotation.Author;
+import org.apache.abdera2.ext.serializer.annotation.BaseURI;
+import org.apache.abdera2.ext.serializer.annotation.Categories;
+import org.apache.abdera2.ext.serializer.annotation.Category;
+import org.apache.abdera2.ext.serializer.annotation.Collection;
+import org.apache.abdera2.ext.serializer.annotation.Content;
+import org.apache.abdera2.ext.serializer.annotation.Contributor;
+import org.apache.abdera2.ext.serializer.annotation.Control;
+import org.apache.abdera2.ext.serializer.annotation.DateTime;
+import org.apache.abdera2.ext.serializer.annotation.Draft;
+import org.apache.abdera2.ext.serializer.annotation.Edited;
+import org.apache.abdera2.ext.serializer.annotation.Email;
+import org.apache.abdera2.ext.serializer.annotation.Entry;
+import org.apache.abdera2.ext.serializer.annotation.Extension;
+import org.apache.abdera2.ext.serializer.annotation.Generator;
+import org.apache.abdera2.ext.serializer.annotation.HrefLanguage;
+import org.apache.abdera2.ext.serializer.annotation.ID;
+import org.apache.abdera2.ext.serializer.annotation.IRI;
+import org.apache.abdera2.ext.serializer.annotation.Icon;
+import org.apache.abdera2.ext.serializer.annotation.Label;
+import org.apache.abdera2.ext.serializer.annotation.Language;
+import org.apache.abdera2.ext.serializer.annotation.Length;
+import org.apache.abdera2.ext.serializer.annotation.Link;
+import org.apache.abdera2.ext.serializer.annotation.Logo;
+import org.apache.abdera2.ext.serializer.annotation.MediaType;
+import org.apache.abdera2.ext.serializer.annotation.Person;
+import org.apache.abdera2.ext.serializer.annotation.Published;
+import org.apache.abdera2.ext.serializer.annotation.Rel;
+import org.apache.abdera2.ext.serializer.annotation.Rights;
+import org.apache.abdera2.ext.serializer.annotation.Scheme;
+import org.apache.abdera2.ext.serializer.annotation.Source;
+import org.apache.abdera2.ext.serializer.annotation.Src;
+import org.apache.abdera2.ext.serializer.annotation.Subtitle;
+import org.apache.abdera2.ext.serializer.annotation.Summary;
+import org.apache.abdera2.ext.serializer.annotation.Text;
+import org.apache.abdera2.ext.serializer.annotation.Title;
+import org.apache.abdera2.ext.serializer.annotation.URI;
+import org.apache.abdera2.ext.serializer.annotation.Updated;
+import org.apache.abdera2.ext.serializer.annotation.Value;
+import org.apache.abdera2.ext.serializer.annotation.Version;
+import org.apache.abdera2.ext.serializer.annotation.Workspace;
+
+public class DefaultConventions extends AbstractConventions {
+
+ private static final long serialVersionUID = 6797950641657672805L;
+
+ private static final Class<?>[] annotations =
+ {Accept.class, Author.class, BaseURI.class, Categories.class, Category.class, Collection.class, Content.class,
+ Contributor.class, Control.class, Draft.class, Edited.class, Email.class, Entry.class, Extension.class,
+ Generator.class, HrefLanguage.class, Icon.class, ID.class, Label.class, Language.class, Length.class,
+ Link.class, Logo.class, MediaType.class, Published.class, Rel.class, Rights.class, Scheme.class, Source.class,
+ Src.class, Subtitle.class, Summary.class, Title.class, Updated.class, URI.class, Value.class, Version.class,
+ Workspace.class, Text.class, DateTime.class, Person.class, IRI.class};
+
+ @SuppressWarnings("unchecked")
+ public DefaultConventions() {
+ super(false);
+ for (Class<?> type : annotations)
+ setConvention((Class<? extends Annotation>)type);
+ }
+
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/DefaultConventions.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/DefaultSerializationContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/DefaultSerializationContext.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/DefaultSerializationContext.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/DefaultSerializationContext.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer;
+
+import java.util.Map;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.Discover;
+import org.apache.abdera2.writer.StreamWriter;
+
+public class DefaultSerializationContext extends AbstractSerializationContext {
+
+ private static final long serialVersionUID = 740460842415905883L;
+
+ private final Iterable<SerializerProvider> providers;
+
+ public DefaultSerializationContext(StreamWriter streamWriter) {
+ super(streamWriter);
+ providers = loadConverterProviders();
+ initSerializers();
+ }
+
+ public DefaultSerializationContext(Abdera abdera, StreamWriter streamWriter) {
+ super(abdera, streamWriter);
+ providers = loadConverterProviders();
+ initSerializers();
+ }
+
+ private void initSerializers() {
+ Iterable<SerializerProvider> providers = getConverterProviders();
+ for (SerializerProvider provider : providers) {
+ for (Map.Entry<Class<?>, Serializer> entry : provider) {
+ setSerializer(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+ /**
+ * Returns the listing of registered ConverterProvider implementations
+ */
+ public Iterable<SerializerProvider> getConverterProviders() {
+ return providers;
+ // return providers != null ?
+ // providers.toArray(
+ // new SerializerProvider[providers.size()]) :
+ // new SerializerProvider[0];
+ }
+
+ protected static synchronized Iterable<SerializerProvider> loadConverterProviders() {
+ Iterable<SerializerProvider> providers = Discover.locate("org.apache.abdera.converter.ConverterProvider");
+ // ServiceUtil.loadimpls(
+ // "META-INF/services/org.apache.abdera.converter.ConverterProvider");
+ return providers;
+ }
+
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/DefaultSerializationContext.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ObjectContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ObjectContext.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ObjectContext.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ObjectContext.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@SuppressWarnings("unchecked")
+public class ObjectContext {
+
+ private final Class<?> objectType;
+ private final Object parent;
+ private final AccessibleObject accessor;
+ private final Annotation[] annotations;
+ private final Serializer serializer;
+ private final Field[] fields;
+ private final Method[] methods;
+
+ public ObjectContext(Object object) {
+ this(object, null, null);
+ }
+
+ public ObjectContext(Object object, Object parent, AccessibleObject accessor) {
+ this.objectType =
+ object != null ? object.getClass() : accessor != null ? AbstractSerializationContext
+ .getReturnType(accessor) : null;
+ this.parent = parent;
+ this.accessor = accessor;
+ this.annotations = initAnnotations();
+ this.serializer = initSerializer();
+ this.fields = initFields();
+ this.methods = initMethods();
+ }
+
+ private Field[] initFields() {
+ Field[] fields = objectType.getFields();
+ List<Field> list = new ArrayList<Field>();
+ for (Field field : fields) {
+ int mods = field.getModifiers();
+ // ignore static fields
+ if (!Modifier.isStatic(mods)) {
+ list.add(field);
+ }
+ }
+ return list.toArray(new Field[list.size()]);
+ }
+
+ private Method[] initMethods() {
+ Method[] methods = objectType.getMethods();
+ List<Method> list = new ArrayList<Method>();
+ for (Method method : methods) {
+ // only methods that have no parameters, return a value, are not
+ // abstract and are not static
+ int mods = method.getModifiers();
+ if (!Modifier.isStatic(mods) && !Modifier.isAbstract(mods)
+ && method.getParameterTypes().length == 0
+ && method.getReturnType() != Void.class) {
+ list.add(method);
+ }
+ }
+ return list.toArray(new Method[list.size()]);
+ }
+
+ private Annotation[] initAnnotations() {
+ Map<Class<? extends Annotation>, Annotation> annotations =
+ new HashMap<Class<? extends Annotation>, Annotation>();
+ if (objectType != null) {
+ for (Annotation annotation : objectType.getAnnotations()) {
+ annotations.put(annotation.annotationType(), annotation);
+ }
+ }
+ if (accessor != null) {
+ for (Annotation annotation : accessor.getAnnotations()) {
+ annotations.put(annotation.annotationType(), annotation);
+ }
+ }
+ return annotations.values().toArray(new Annotation[annotations.size()]);
+ }
+
+ private Serializer initSerializer() {
+ try {
+ org.apache.abdera2.ext.serializer.annotation.Serializer ser =
+ getAnnotation(org.apache.abdera2.ext.serializer.annotation.Serializer.class);
+ if (ser != null) {
+ Class<? extends Serializer> serclass = ser.value();
+ return serclass.newInstance();
+ }
+ return null;
+ } catch (Throwable t) {
+ throw new SerializationException(t);
+ }
+ }
+
+ public AccessibleObject getAccessor() {
+ return accessor;
+ }
+
+ public Object getParent() {
+ return parent;
+ }
+
+ public Class<?> getObjectType() {
+ return objectType;
+ }
+
+ public <X extends Annotation> X getAnnotation(Class<X> annotationType) {
+ for (Annotation annotation : annotations) {
+ if (annotation.annotationType() == annotationType)
+ return (X)annotation;
+ }
+ return null;
+ }
+
+ public Annotation[] getAnnotations() {
+ return annotations;
+ }
+
+ public Serializer getSerializer() {
+ return serializer;
+ }
+
+ public Field[] getFields() {
+ return fields;
+ }
+
+ public Method[] getMethods() {
+ return methods;
+ }
+
+ public AccessibleObject[] getAccessors() {
+ List<AccessibleObject> list = new ArrayList<AccessibleObject>();
+ for (Method method : methods)
+ list.add(method);
+ for (Field field : fields)
+ list.add(field);
+ return list.toArray(new AccessibleObject[list.size()]);
+ }
+
+ public AccessibleObject[] getAccessors(Class<? extends Annotation> annotation, Conventions conventions) {
+ List<AccessibleObject> accessors = new ArrayList<AccessibleObject>();
+ for (AccessibleObject accessor : getAccessors()) {
+ if (accessor.isAnnotationPresent(annotation) || annotation.equals(conventions.matchConvention(accessor))) {
+ accessors.add(accessor);
+ }
+ }
+ return accessors.toArray(new AccessibleObject[accessors.size()]);
+ }
+
+ public AccessibleObject getAccessor(Class<? extends Annotation> annotation, Conventions conventions) {
+ for (AccessibleObject accessor : getAccessors()) {
+ if (accessor.isAnnotationPresent(annotation) || annotation.equals(conventions.matchConvention(accessor))) {
+ return accessor;
+ }
+ }
+ return null;
+ }
+
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ObjectContext.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ObjectResponseContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ObjectResponseContext.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ObjectResponseContext.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ObjectResponseContext.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer;
+
+import java.io.IOException;
+import java.lang.reflect.AccessibleObject;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.date.DateTime;
+import org.apache.abdera2.ext.serializer.annotation.EntityTag;
+import org.apache.abdera2.ext.serializer.annotation.LastModified;
+import org.apache.abdera2.ext.serializer.annotation.MediaType;
+import org.apache.abdera2.protocol.server.context.StreamWriterResponseContext;
+import org.apache.abdera2.writer.StreamWriter;
+
+public class ObjectResponseContext extends StreamWriterResponseContext {
+
+ private final Object object;
+ private final ObjectContext objectContext;
+ private final Conventions conventions;
+ private final Class<? extends SerializationContext> context;
+
+ public ObjectResponseContext(Object object, Abdera abdera, String encoding, String sw) {
+ this(object, null, null, abdera, encoding, sw);
+ }
+
+ public ObjectResponseContext(Object object,
+ Class<? extends SerializationContext> context,
+ Conventions conventions,
+ Abdera abdera,
+ String encoding,
+ String sw) {
+ super(abdera, encoding, sw);
+ this.object = object;
+ this.objectContext = new ObjectContext(object);
+ this.conventions = conventions != null ? conventions : new DefaultConventions();
+ this.context = context != null ? context : ConventionSerializationContext.class;
+ init();
+ }
+
+ public ObjectResponseContext(Object object, Abdera abdera, String encoding) {
+ this(object, null, null, abdera, encoding, null);
+ }
+
+ public ObjectResponseContext(Object object,
+ Class<? extends SerializationContext> context,
+ Conventions conventions,
+ Abdera abdera,
+ String encoding) {
+ this(object, context, conventions, abdera, encoding, null);
+ }
+
+ public ObjectResponseContext(Object object, Abdera abdera) {
+ this(object, null, null, abdera, null, null);
+ }
+
+ public ObjectResponseContext(Object object,
+ Class<? extends SerializationContext> context,
+ Conventions conventions,
+ Abdera abdera) {
+ this(object, context, null, abdera, null, null);
+ }
+
+ private void init() {
+ setContentType(getObjectContentType());
+ setEntityTag(getObjectEntityTag());
+ setLastModified(getObjectLastModified());
+ }
+
+ private Date getObjectLastModified() {
+ Date date = null;
+ AccessibleObject accessor = objectContext.getAccessor(LastModified.class, conventions);
+ if (accessor != null) {
+ Object value = BaseSerializer.eval(accessor, object);
+ date = getDate(value);
+ }
+ return date;
+ }
+
+ private Date getDate(Object value) {
+ Date date = null;
+ if (value == null)
+ return null;
+ if (value instanceof Date) {
+ date = (Date)value;
+ } else if (value instanceof Calendar) {
+ date = ((Calendar)value).getTime();
+ } else if (value instanceof Long) {
+ date = new Date(((Long)value).longValue());
+ } else if (value instanceof String) {
+ date = DateTime.parse((String)value);
+ } else {
+ date = DateTime.parse(value.toString());
+ }
+ return date;
+ }
+
+ private String getObjectEntityTag() {
+ String etag = null;
+ AccessibleObject accessor = objectContext.getAccessor(EntityTag.class, conventions);
+ if (accessor != null) {
+ Object value = BaseSerializer.eval(accessor, object);
+ etag = value != null ? BaseSerializer.toString(value) : null;
+ }
+ return etag;
+ }
+
+ private String getObjectContentType() {
+ String ctype = null;
+ AccessibleObject accessor = objectContext.getAccessor(MediaType.class, conventions);
+ if (accessor != null) {
+ Object value = BaseSerializer.eval(accessor, object);
+ ctype = value != null ? BaseSerializer.toString(value) : null;
+ }
+ if (ctype == null) {
+ MediaType content_type = objectContext.getAnnotation(MediaType.class);
+ if (content_type != null && !content_type.value().equals(BaseSerializer.DEFAULT)) {
+ ctype = content_type.value();
+ }
+ }
+ return ctype;
+ }
+
+ @Override
+ protected void writeTo(StreamWriter sw) throws IOException {
+ SerializationContext context = newSerializationContext(getAbdera(), conventions, sw);
+ sw.startDocument();
+ context.serialize(object, objectContext);
+ sw.endDocument();
+ }
+
+ private SerializationContext newSerializationContext(Abdera abdera, Conventions conventions, StreamWriter sw) {
+ try {
+ return context.getConstructor(Abdera.class, Conventions.class, StreamWriter.class).newInstance(abdera,
+ conventions,
+ sw);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ObjectResponseContext.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializationContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializationContext.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializationContext.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializationContext.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer;
+
+import java.io.Serializable;
+import java.lang.reflect.AccessibleObject;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.writer.StreamWriter;
+
+public interface SerializationContext extends Serializable {
+
+ Abdera getAbdera();
+
+ StreamWriter getStreamWriter();
+
+ void serialize(Object object);
+
+ void serialize(Object object, ObjectContext objectContext);
+
+ void serialize(Object object, Serializer serializer);
+
+ void serialize(Object object, ObjectContext objectContext, Serializer serializer);
+
+ void setSerializer(Class<?> type, Serializer serializer);
+
+ Serializer getSerializer(ObjectContext objectContext);
+
+ boolean hasSerializer(ObjectContext objectContext);
+
+ boolean hasSerializer(Object object);
+
+ boolean hasSerializer(Object object, Object parent, AccessibleObject accessor);
+
+ boolean hasSerializer(Class<?> type);
+
+ boolean hasSerializer(AccessibleObject accessor);
+
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializationContext.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializationException.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializationException.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializationException.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializationException.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer;
+
+public class SerializationException extends RuntimeException {
+
+ private static final long serialVersionUID = 3399703987771955406L;
+
+ public SerializationException() {
+ super();
+ }
+
+ public SerializationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public SerializationException(String message) {
+ super(message);
+ }
+
+ public SerializationException(Throwable cause) {
+ super(cause);
+ }
+
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializationException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/Serializer.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/Serializer.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/Serializer.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/Serializer.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer;
+
+public abstract class Serializer {
+
+ /**
+ * Serializes the given object to the specified writer
+ */
+ public void serialize(Object object, SerializationContext serializationContext) {
+ serialize(object, new ObjectContext(object), serializationContext);
+ }
+
+ /**
+ * Serializes the given object to the specified writer
+ */
+ public abstract void serialize(Object object, ObjectContext context, SerializationContext serializationContext);
+
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/Serializer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializerProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializerProvider.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializerProvider.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializerProvider.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+public abstract class SerializerProvider implements Iterable<Map.Entry<Class<?>, Serializer>> {
+
+ protected Map<Class<?>, Serializer> serializers = new HashMap<Class<?>, Serializer>();
+
+ protected void setConverter(Class<?> type, Serializer serializer) {
+ serializers.put(type, serializer);
+ }
+
+ public Iterator<Entry<Class<?>, Serializer>> iterator() {
+ return serializers.entrySet().iterator();
+ }
+
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/SerializerProvider.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/annotation/Accept.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/annotation/Accept.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/annotation/Accept.java (added)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/annotation/Accept.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer.annotation;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Retention(RUNTIME)
+@Target( {METHOD, FIELD})
+@Convention(".*accept")
+public @interface Accept {
+}
Propchange: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/annotation/Accept.java
------------------------------------------------------------------------------
svn:mime-type = text/plain