You are viewing a plain text version of this content. The canonical link for it is here.
Posted to graffito-commits@incubator.apache.org by cl...@apache.org on 2006/09/20 19:37:21 UTC
svn commit: r448311 [15/25] - in /incubator/graffito/trunk: ./ api/
api/src/java/org/apache/portals/graffito/context/
api/src/java/org/apache/portals/graffito/exception/
api/src/java/org/apache/portals/graffito/services/core/
api/src/java/org/apache/po...
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java?view=diff&rev=448311&r1=448310&r2=448311
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java Wed Sep 20 12:37:05 2006
@@ -1,283 +1,283 @@
-/*
- * Copyright 2000-2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.portals.graffito.jcr.mapper.impl;
-
-
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.portals.graffito.jcr.exception.InitMapperException;
-import org.apache.portals.graffito.jcr.exception.JcrMappingException;
-import org.apache.portals.graffito.jcr.mapper.Mapper;
-import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
-import org.apache.portals.graffito.jcr.mapper.model.MappingDescriptor;
-
-/**
- *
- * Digester implementation for {@link org.apache.portals.graffito.jcr.mapper.Mapper}
- *
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
- * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
- */
-public class DigesterMapperImpl implements Mapper {
- private static final Log log = LogFactory.getLog(DigesterMapperImpl.class);
-
- private MappingDescriptor mappingDescriptor;
- private Collection rootClassDescriptors = new ArrayList(); // contains the class descriptor which have not ancestors
-
- private String[] mappingFiles;
- private InputStream[] mappingStreams;
- private DigesterDescriptorReader descriptorReader;
-
- /**
- * No-arg constructor.
- */
- public DigesterMapperImpl() {
- }
-
- /**
- * Constructor
- *
- * @param xmlFile The xml mapping file to read
- *
- */
- public DigesterMapperImpl(String xmlFile) {
- this.mappingFiles = new String[] { xmlFile };
- this.buildMapper();
- }
-
- /**
- * Constructor
- *
- * @param files a set of xml mapping files to read
- *
- */
- public DigesterMapperImpl(String[] files) {
- this.mappingFiles = files;
- this.buildMapper();
- }
-
- /**
- * Constructor
- *
- * @param stream The xml mapping file to read
- */
- public DigesterMapperImpl(InputStream stream) {
- this.mappingStreams = new InputStream[] { stream };
- this.buildMapper();
- }
-
- /**
- * Constructor
- *
- * @param streams a set of mapping files to read
- *
- */
- public DigesterMapperImpl(InputStream[] streams) {
- this.mappingStreams = streams;
- this.buildMapper();
- }
-
- /**
- * Set a mapping file.
- *
- * @param file path to mapping file
- */
- public void setMappingFile(String file) {
- setMappingFiles(new String[] { file });
- this.buildMapper();
- }
-
- /**
- *
- * @param files
- */
- public void setMappingFiles(String[] files) {
- this.mappingFiles = files;
- }
-
- public void setMappingStream(InputStream stream) {
- setMappingStreams(new InputStream[] { stream });
- }
-
- public void setMappingStreams(InputStream[] streams) {
- this.mappingStreams = streams;
- }
-
- public void setDescriptorReader(DigesterDescriptorReader reader) {
- this.descriptorReader = reader;
- }
-
- private Mapper buildMapper() {
- if (this.descriptorReader == null) {
- this.descriptorReader = new DigesterDescriptorReader();
- }
- if (this.mappingFiles != null && this.mappingFiles.length > 0) {
- log.info("Read the xml mapping file : " + this.mappingFiles[0]);
- this.mappingDescriptor = this.descriptorReader.loadClassDescriptors(this.mappingFiles[0]);
- this.mappingDescriptor.setMapper(this);
-
- for (int i = 1; i < this.mappingFiles.length; i++) {
- log.info("Read the xml mapping file : " + this.mappingFiles[i]);
- MappingDescriptor anotherMappingDescriptor = this.descriptorReader.loadClassDescriptors(this.mappingFiles[i]);
- this.mappingDescriptor.getClassDescriptorsByClassName().putAll(anotherMappingDescriptor.getClassDescriptorsByClassName());
- this.mappingDescriptor.getClassDescriptorsByNodeType().putAll(anotherMappingDescriptor.getClassDescriptorsByNodeType());
-
- }
- }
- else if (this.mappingStreams != null && this.mappingStreams.length > 0) {
- log.info("Read the stream mapping file : " + this.mappingStreams[0].toString());
- this.mappingDescriptor = this.descriptorReader.loadClassDescriptors(this.mappingStreams[0]);
- this.mappingDescriptor.setMapper(this);
-
- for (int i = 1; i < this.mappingStreams.length; i++) {
- log.info("Read the stream mapping file : " + this.mappingStreams[i].toString());
- MappingDescriptor anotherMappingDescriptor = this.descriptorReader.loadClassDescriptors(this.mappingStreams[i]);
- this.mappingDescriptor.getClassDescriptorsByClassName().putAll(anotherMappingDescriptor.getClassDescriptorsByClassName());
- this.mappingDescriptor.getClassDescriptorsByNodeType().putAll(anotherMappingDescriptor.getClassDescriptorsByNodeType());
- }
- }
- if (null != this.mappingDescriptor) {
- List errors = new ArrayList();
- errors = solveReferences(errors);
- errors = validateDescriptors(errors, rootClassDescriptors);
-
- if (!errors.isEmpty()) {
- throw new InitMapperException("Mapping files contain errors."
- + getErrorMessage(errors));
- }
- }
- else {
- throw new InitMapperException("No mappings were provided");
- }
-
- return this;
- }
-
- private List solveReferences(List errors) {
- for(Iterator it = this.mappingDescriptor.getClassDescriptorsByClassName().entrySet().iterator(); it.hasNext(); ) {
- Map.Entry entry = (Map.Entry) it.next();
- ClassDescriptor cd = (ClassDescriptor) entry.getValue();
-
- if (null != cd.getExtend() && !"".equals(cd.getExtend()))
- {
- ClassDescriptor superClassDescriptor = this.mappingDescriptor.getClassDescriptorByName(cd.getExtend());
-
- if (null == superClassDescriptor)
- {
- errors.add("Cannot find mapping for class "
- + cd.getExtend()
- + " referenced as extends from "
- + cd.getClassName());
- }
- else
- {
- log.debug("Class " +cd.getClassName() + " extends " + cd.getExtend());
- cd.setSuperClassDescriptor(superClassDescriptor);
- }
- }
- else
- {
- rootClassDescriptors.add(cd);
- }
-
- Collection interfaces = cd.getImplements();
- if (interfaces.size() > 0)
- {
- for (Iterator iterator = interfaces.iterator(); iterator.hasNext();)
- {
- String interfaceName= (String) iterator.next();
- ClassDescriptor interfaceClassDescriptor = this.mappingDescriptor.getClassDescriptorByName(interfaceName);
-
- if (null == interfaceClassDescriptor)
- {
- errors.add("Cannot find mapping for interface "
- + interfaceName
- + " referenced as implements from "
- + cd.getClassName());
- }
- else
- {
- log.debug("Class " +cd.getClassName() + " implements " + interfaceName);
- //cd.setSuperClassDescriptor(interfaceClassDescriptor);
- interfaceClassDescriptor.addDescendantClassDescriptor(cd);
- }
-
- }
- }
-
- }
-
- return errors;
- }
-
- /**
- * Validate all class descriptors.
- * This method validates the toplevel ancestors and after the descendants.
- * Otherwise, we can have invalid settings in the class descriptors
- * @param errors all errors found during the validation process
- * @param classDescriptors the ancestor classdescriptors
- * @return
- */
- private List validateDescriptors(List errors, Collection classDescriptors ) {
- for(Iterator it = classDescriptors.iterator(); it.hasNext(); ) {
- ClassDescriptor classDescriptor = (ClassDescriptor) it.next();
- try {
- classDescriptor.afterPropertiesSet();
- if (classDescriptor.hasDescendants()) {
- errors = validateDescriptors(errors, classDescriptor.getDescendantClassDescriptors());
- }
- }
- catch(JcrMappingException jme) {
- log.warn("Mapping of class " + classDescriptor.getClassName() + " is invalid", jme);
- errors.add(jme.getMessage());
- }
- }
- return errors;
- }
-
- private String getErrorMessage(List errors) {
- final String lineSep = System.getProperty("line.separator");
- StringBuffer buf = new StringBuffer();
- for(Iterator it = errors.iterator(); it.hasNext();) {
- buf.append(lineSep).append(it.next());
- }
-
- return buf.toString();
- }
-
- /**
- *
- * @see org.apache.portals.graffito.jcr.mapper.Mapper#getClassDescriptorByClass(java.lang.Class)
- */
- public ClassDescriptor getClassDescriptorByClass(Class clazz) {
- return mappingDescriptor.getClassDescriptorByName(clazz.getName());
- }
-
- /**
- * @see org.apache.portals.graffito.jcr.mapper.Mapper#getClassDescriptorByNodeType(String)
- */
- public ClassDescriptor getClassDescriptorByNodeType(String jcrNodeType) {
- return mappingDescriptor.getClassDescriptorByNodeType(jcrNodeType);
- }
-
-}
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.mapper.impl;
+
+
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.exception.InitMapperException;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.MappingDescriptor;
+
+/**
+ *
+ * Digester implementation for {@link org.apache.portals.graffito.jcr.mapper.Mapper}
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ */
+public class DigesterMapperImpl implements Mapper {
+ private static final Log log = LogFactory.getLog(DigesterMapperImpl.class);
+
+ private MappingDescriptor mappingDescriptor;
+ private Collection rootClassDescriptors = new ArrayList(); // contains the class descriptor which have not ancestors
+
+ private String[] mappingFiles;
+ private InputStream[] mappingStreams;
+ private DigesterDescriptorReader descriptorReader;
+
+ /**
+ * No-arg constructor.
+ */
+ public DigesterMapperImpl() {
+ }
+
+ /**
+ * Constructor
+ *
+ * @param xmlFile The xml mapping file to read
+ *
+ */
+ public DigesterMapperImpl(String xmlFile) {
+ this.mappingFiles = new String[] { xmlFile };
+ this.buildMapper();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param files a set of xml mapping files to read
+ *
+ */
+ public DigesterMapperImpl(String[] files) {
+ this.mappingFiles = files;
+ this.buildMapper();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param stream The xml mapping file to read
+ */
+ public DigesterMapperImpl(InputStream stream) {
+ this.mappingStreams = new InputStream[] { stream };
+ this.buildMapper();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param streams a set of mapping files to read
+ *
+ */
+ public DigesterMapperImpl(InputStream[] streams) {
+ this.mappingStreams = streams;
+ this.buildMapper();
+ }
+
+ /**
+ * Set a mapping file.
+ *
+ * @param file path to mapping file
+ */
+ public void setMappingFile(String file) {
+ setMappingFiles(new String[] { file });
+ this.buildMapper();
+ }
+
+ /**
+ *
+ * @param files
+ */
+ public void setMappingFiles(String[] files) {
+ this.mappingFiles = files;
+ }
+
+ public void setMappingStream(InputStream stream) {
+ setMappingStreams(new InputStream[] { stream });
+ }
+
+ public void setMappingStreams(InputStream[] streams) {
+ this.mappingStreams = streams;
+ }
+
+ public void setDescriptorReader(DigesterDescriptorReader reader) {
+ this.descriptorReader = reader;
+ }
+
+ private Mapper buildMapper() {
+ if (this.descriptorReader == null) {
+ this.descriptorReader = new DigesterDescriptorReader();
+ }
+ if (this.mappingFiles != null && this.mappingFiles.length > 0) {
+ log.info("Read the xml mapping file : " + this.mappingFiles[0]);
+ this.mappingDescriptor = this.descriptorReader.loadClassDescriptors(this.mappingFiles[0]);
+ this.mappingDescriptor.setMapper(this);
+
+ for (int i = 1; i < this.mappingFiles.length; i++) {
+ log.info("Read the xml mapping file : " + this.mappingFiles[i]);
+ MappingDescriptor anotherMappingDescriptor = this.descriptorReader.loadClassDescriptors(this.mappingFiles[i]);
+ this.mappingDescriptor.getClassDescriptorsByClassName().putAll(anotherMappingDescriptor.getClassDescriptorsByClassName());
+ this.mappingDescriptor.getClassDescriptorsByNodeType().putAll(anotherMappingDescriptor.getClassDescriptorsByNodeType());
+
+ }
+ }
+ else if (this.mappingStreams != null && this.mappingStreams.length > 0) {
+ log.info("Read the stream mapping file : " + this.mappingStreams[0].toString());
+ this.mappingDescriptor = this.descriptorReader.loadClassDescriptors(this.mappingStreams[0]);
+ this.mappingDescriptor.setMapper(this);
+
+ for (int i = 1; i < this.mappingStreams.length; i++) {
+ log.info("Read the stream mapping file : " + this.mappingStreams[i].toString());
+ MappingDescriptor anotherMappingDescriptor = this.descriptorReader.loadClassDescriptors(this.mappingStreams[i]);
+ this.mappingDescriptor.getClassDescriptorsByClassName().putAll(anotherMappingDescriptor.getClassDescriptorsByClassName());
+ this.mappingDescriptor.getClassDescriptorsByNodeType().putAll(anotherMappingDescriptor.getClassDescriptorsByNodeType());
+ }
+ }
+ if (null != this.mappingDescriptor) {
+ List errors = new ArrayList();
+ errors = solveReferences(errors);
+ errors = validateDescriptors(errors, rootClassDescriptors);
+
+ if (!errors.isEmpty()) {
+ throw new InitMapperException("Mapping files contain errors."
+ + getErrorMessage(errors));
+ }
+ }
+ else {
+ throw new InitMapperException("No mappings were provided");
+ }
+
+ return this;
+ }
+
+ private List solveReferences(List errors) {
+ for(Iterator it = this.mappingDescriptor.getClassDescriptorsByClassName().entrySet().iterator(); it.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) it.next();
+ ClassDescriptor cd = (ClassDescriptor) entry.getValue();
+
+ if (null != cd.getExtend() && !"".equals(cd.getExtend()))
+ {
+ ClassDescriptor superClassDescriptor = this.mappingDescriptor.getClassDescriptorByName(cd.getExtend());
+
+ if (null == superClassDescriptor)
+ {
+ errors.add("Cannot find mapping for class "
+ + cd.getExtend()
+ + " referenced as extends from "
+ + cd.getClassName());
+ }
+ else
+ {
+ log.debug("Class " +cd.getClassName() + " extends " + cd.getExtend());
+ cd.setSuperClassDescriptor(superClassDescriptor);
+ }
+ }
+ else
+ {
+ rootClassDescriptors.add(cd);
+ }
+
+ Collection interfaces = cd.getImplements();
+ if (interfaces.size() > 0)
+ {
+ for (Iterator iterator = interfaces.iterator(); iterator.hasNext();)
+ {
+ String interfaceName= (String) iterator.next();
+ ClassDescriptor interfaceClassDescriptor = this.mappingDescriptor.getClassDescriptorByName(interfaceName);
+
+ if (null == interfaceClassDescriptor)
+ {
+ errors.add("Cannot find mapping for interface "
+ + interfaceName
+ + " referenced as implements from "
+ + cd.getClassName());
+ }
+ else
+ {
+ log.debug("Class " +cd.getClassName() + " implements " + interfaceName);
+ //cd.setSuperClassDescriptor(interfaceClassDescriptor);
+ interfaceClassDescriptor.addDescendantClassDescriptor(cd);
+ }
+
+ }
+ }
+
+ }
+
+ return errors;
+ }
+
+ /**
+ * Validate all class descriptors.
+ * This method validates the toplevel ancestors and after the descendants.
+ * Otherwise, we can have invalid settings in the class descriptors
+ * @param errors all errors found during the validation process
+ * @param classDescriptors the ancestor classdescriptors
+ * @return
+ */
+ private List validateDescriptors(List errors, Collection classDescriptors ) {
+ for(Iterator it = classDescriptors.iterator(); it.hasNext(); ) {
+ ClassDescriptor classDescriptor = (ClassDescriptor) it.next();
+ try {
+ classDescriptor.afterPropertiesSet();
+ if (classDescriptor.hasDescendants()) {
+ errors = validateDescriptors(errors, classDescriptor.getDescendantClassDescriptors());
+ }
+ }
+ catch(JcrMappingException jme) {
+ log.warn("Mapping of class " + classDescriptor.getClassName() + " is invalid", jme);
+ errors.add(jme.getMessage());
+ }
+ }
+ return errors;
+ }
+
+ private String getErrorMessage(List errors) {
+ final String lineSep = System.getProperty("line.separator");
+ StringBuffer buf = new StringBuffer();
+ for(Iterator it = errors.iterator(); it.hasNext();) {
+ buf.append(lineSep).append(it.next());
+ }
+
+ return buf.toString();
+ }
+
+ /**
+ *
+ * @see org.apache.portals.graffito.jcr.mapper.Mapper#getClassDescriptorByClass(java.lang.Class)
+ */
+ public ClassDescriptor getClassDescriptorByClass(Class clazz) {
+ return mappingDescriptor.getClassDescriptorByName(clazz.getName());
+ }
+
+ /**
+ * @see org.apache.portals.graffito.jcr.mapper.Mapper#getClassDescriptorByNodeType(String)
+ */
+ public ClassDescriptor getClassDescriptorByNodeType(String jcrNodeType) {
+ return mappingDescriptor.getClassDescriptorByNodeType(jcrNodeType);
+ }
+
+}
Propchange: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java?view=diff&rev=448311&r1=448310&r2=448311
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java Wed Sep 20 12:37:05 2006
@@ -1,268 +1,268 @@
-/*
- * Copyright 2000-2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.portals.graffito.jcr.mapper.model;
-
-
-import org.apache.portals.graffito.jcr.persistence.objectconverter.BeanConverter;
-import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ObjectConverterImpl;
-import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
-
-/**
- * BeanDescriptor is used by the mapper to read general information on a bean field
- *
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
- * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
- */
-public class BeanDescriptor {
- private ClassDescriptor classDescriptor;
-
- private String fieldName;
- private String jcrName;
- private boolean proxy;
- private boolean autoRetrieve = true;
- private boolean autoUpdate = true;
- private boolean autoInsert = true;
- private boolean inline;
- private String converter;
- private BeanConverter beanConverter;
- private String jcrNodeType;
- private boolean jcrAutoCreated;
- private boolean jcrMandatory;
- private String jcrOnParentVersion;
- private boolean jcrProtected;
- private boolean jcrSameNameSiblings;
-
- /**
- * @return Returns the fieldName.
- */
- public String getFieldName() {
- return fieldName;
- }
-
- /**
- * @param fieldName The fieldName to set.
- */
- public void setFieldName(String fieldName) {
- this.fieldName = fieldName;
- }
-
- /**
- * @return Returns the jcrName.
- */
- public String getJcrName() {
- return jcrName;
- }
-
- /**
- * @param jcrName The jcrName to set.
- */
- public void setJcrName(String jcrName) {
- this.jcrName = jcrName;
- }
-
- /**
- * @return Returns the proxy.
- */
- public boolean isProxy() {
- return proxy;
- }
-
- /**
- * @param proxy The proxy to set.
- */
- public void setProxy(boolean proxy) {
- this.proxy = proxy;
- }
-
-
- public boolean isAutoInsert() {
- return autoInsert;
- }
-
- public void setAutoInsert(boolean autoInsert) {
- this.autoInsert = autoInsert;
- }
-
- public boolean isAutoRetrieve() {
- return autoRetrieve;
- }
-
- public void setAutoRetrieve(boolean autoRetrieve) {
- this.autoRetrieve = autoRetrieve;
- }
-
- public boolean isAutoUpdate() {
- return autoUpdate;
- }
-
- public void setAutoUpdate(boolean autoUpdate) {
- this.autoUpdate = autoUpdate;
- }
-
- /**
- * Are the current bean properties inlined in the parent
- *
- * @return <tt>true</tt> if bean's properties are inlined in the parent node
- */
- public boolean isInline() {
- return this.inline;
- }
-
- /**
- * Sets if the bean's properties should be inlined in the parent
- * instead of being persisted on a subnode
- *
- * @param flag <tt>true</tt> if the bean properties should be inlined
- */
- public void setInline(boolean flag) {
- this.inline = flag;
- }
-
- /**
- * Get the <code>BeanConverter</code> fully qualified name or <tt>null</tt>
- * if none specified by the bean descriptor.
- *
- * @return fully qualified class name or <tt>null</tt>
- */
- public String getConverter() {
- return this.converter;
- }
-
- /**
- * Sets the fully qualified name of a <code>BeanConverter</code> to be used.
- *
- * @param converterClass a fully qualified class name
- */
- public void setConverter(String converterClass) {
- this.converter = converterClass;
- }
-
-
- /** Getter for property jcrNodeType.
- *
- * @return jcrNodeType
- */
- public String getJcrNodeType() {
- return jcrNodeType;
- }
-
- /** Setter for property jcrNodeType.
- *
- * @param value jcrNodeType
- */
- public void setJcrNodeType(String value) {
- this.jcrNodeType = value;
- }
-
- /** Getter for property jcrAutoCreated.
- *
- * @return jcrAutoCreated
- */
- public boolean isJcrAutoCreated() {
- return jcrAutoCreated;
- }
-
- /** Setter for property jcrAutoCreated.
- *
- * @param value jcrAutoCreated
- */
- public void setJcrAutoCreated(boolean value) {
- this.jcrAutoCreated = value;
- }
-
- /** Getter for property jcrMandatory.
- *
- * @return jcrMandatory
- */
- public boolean isJcrMandatory() {
- return jcrMandatory;
- }
-
- /** Setter for property jcrMandatory.
- *
- * @param value jcrMandatory
- */
- public void setJcrMandatory(boolean value) {
- this.jcrMandatory = value;
- }
-
- /** Getter for property jcrOnParentVersion.
- *
- * @return jcrOnParentVersion
- */
- public String getJcrOnParentVersion() {
- return jcrOnParentVersion;
- }
-
- /** Setter for property jcrOnParentVersion.
- *
- * @param value jcrOnParentVersion
- */
- public void setJcrOnParentVersion(String value) {
- this.jcrOnParentVersion = value;
- }
-
- /** Getter for property jcrProtected.
- *
- * @return jcrProtected
- */
- public boolean isJcrProtected() {
- return jcrProtected;
- }
-
- /** Setter for property jcrProtected.
- *
- * @param value jcrProtected
- */
- public void setJcrProtected(boolean value) {
- this.jcrProtected = value;
- }
-
- /** Getter for property jcrSameNameSiblings.
- *
- * @return jcrSameNameSiblings
- */
- public boolean isJcrSameNameSiblings() {
- return jcrSameNameSiblings;
- }
-
- /** Setter for property jcrSameNameSiblings.
- *
- * @param value jcrSameNameSiblings
- */
- public void setJcrSameNameSiblings(boolean value) {
- this.jcrSameNameSiblings = value;
- }
-
- /**
- * @param descriptor
- */
- public void setClassDescriptor(ClassDescriptor descriptor) {
- this.classDescriptor = descriptor;
- }
-
- /**
- * @return Returns the classDescriptor.
- */
- public ClassDescriptor getClassDescriptor() {
- return classDescriptor;
- }
-
- public String toString() {
-
- return "Bean Descriptor : " + this.fieldName;
- }
-}
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.mapper.model;
+
+
+import org.apache.portals.graffito.jcr.persistence.objectconverter.BeanConverter;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ObjectConverterImpl;
+import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
+
+/**
+ * BeanDescriptor is used by the mapper to read general information on a bean field
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ */
+public class BeanDescriptor {
+ private ClassDescriptor classDescriptor;
+
+ private String fieldName;
+ private String jcrName;
+ private boolean proxy;
+ private boolean autoRetrieve = true;
+ private boolean autoUpdate = true;
+ private boolean autoInsert = true;
+ private boolean inline;
+ private String converter;
+ private BeanConverter beanConverter;
+ private String jcrNodeType;
+ private boolean jcrAutoCreated;
+ private boolean jcrMandatory;
+ private String jcrOnParentVersion;
+ private boolean jcrProtected;
+ private boolean jcrSameNameSiblings;
+
+ /**
+ * @return Returns the fieldName.
+ */
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ /**
+ * @param fieldName The fieldName to set.
+ */
+ public void setFieldName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ /**
+ * @return Returns the jcrName.
+ */
+ public String getJcrName() {
+ return jcrName;
+ }
+
+ /**
+ * @param jcrName The jcrName to set.
+ */
+ public void setJcrName(String jcrName) {
+ this.jcrName = jcrName;
+ }
+
+ /**
+ * @return Returns the proxy.
+ */
+ public boolean isProxy() {
+ return proxy;
+ }
+
+ /**
+ * @param proxy The proxy to set.
+ */
+ public void setProxy(boolean proxy) {
+ this.proxy = proxy;
+ }
+
+
+ public boolean isAutoInsert() {
+ return autoInsert;
+ }
+
+ public void setAutoInsert(boolean autoInsert) {
+ this.autoInsert = autoInsert;
+ }
+
+ public boolean isAutoRetrieve() {
+ return autoRetrieve;
+ }
+
+ public void setAutoRetrieve(boolean autoRetrieve) {
+ this.autoRetrieve = autoRetrieve;
+ }
+
+ public boolean isAutoUpdate() {
+ return autoUpdate;
+ }
+
+ public void setAutoUpdate(boolean autoUpdate) {
+ this.autoUpdate = autoUpdate;
+ }
+
+ /**
+ * Are the current bean properties inlined in the parent
+ *
+ * @return <tt>true</tt> if bean's properties are inlined in the parent node
+ */
+ public boolean isInline() {
+ return this.inline;
+ }
+
+ /**
+ * Sets if the bean's properties should be inlined in the parent
+ * instead of being persisted on a subnode
+ *
+ * @param flag <tt>true</tt> if the bean properties should be inlined
+ */
+ public void setInline(boolean flag) {
+ this.inline = flag;
+ }
+
+ /**
+ * Get the <code>BeanConverter</code> fully qualified name or <tt>null</tt>
+ * if none specified by the bean descriptor.
+ *
+ * @return fully qualified class name or <tt>null</tt>
+ */
+ public String getConverter() {
+ return this.converter;
+ }
+
+ /**
+ * Sets the fully qualified name of a <code>BeanConverter</code> to be used.
+ *
+ * @param converterClass a fully qualified class name
+ */
+ public void setConverter(String converterClass) {
+ this.converter = converterClass;
+ }
+
+
+ /** Getter for property jcrNodeType.
+ *
+ * @return jcrNodeType
+ */
+ public String getJcrNodeType() {
+ return jcrNodeType;
+ }
+
+ /** Setter for property jcrNodeType.
+ *
+ * @param value jcrNodeType
+ */
+ public void setJcrNodeType(String value) {
+ this.jcrNodeType = value;
+ }
+
+ /** Getter for property jcrAutoCreated.
+ *
+ * @return jcrAutoCreated
+ */
+ public boolean isJcrAutoCreated() {
+ return jcrAutoCreated;
+ }
+
+ /** Setter for property jcrAutoCreated.
+ *
+ * @param value jcrAutoCreated
+ */
+ public void setJcrAutoCreated(boolean value) {
+ this.jcrAutoCreated = value;
+ }
+
+ /** Getter for property jcrMandatory.
+ *
+ * @return jcrMandatory
+ */
+ public boolean isJcrMandatory() {
+ return jcrMandatory;
+ }
+
+ /** Setter for property jcrMandatory.
+ *
+ * @param value jcrMandatory
+ */
+ public void setJcrMandatory(boolean value) {
+ this.jcrMandatory = value;
+ }
+
+ /** Getter for property jcrOnParentVersion.
+ *
+ * @return jcrOnParentVersion
+ */
+ public String getJcrOnParentVersion() {
+ return jcrOnParentVersion;
+ }
+
+ /** Setter for property jcrOnParentVersion.
+ *
+ * @param value jcrOnParentVersion
+ */
+ public void setJcrOnParentVersion(String value) {
+ this.jcrOnParentVersion = value;
+ }
+
+ /** Getter for property jcrProtected.
+ *
+ * @return jcrProtected
+ */
+ public boolean isJcrProtected() {
+ return jcrProtected;
+ }
+
+ /** Setter for property jcrProtected.
+ *
+ * @param value jcrProtected
+ */
+ public void setJcrProtected(boolean value) {
+ this.jcrProtected = value;
+ }
+
+ /** Getter for property jcrSameNameSiblings.
+ *
+ * @return jcrSameNameSiblings
+ */
+ public boolean isJcrSameNameSiblings() {
+ return jcrSameNameSiblings;
+ }
+
+ /** Setter for property jcrSameNameSiblings.
+ *
+ * @param value jcrSameNameSiblings
+ */
+ public void setJcrSameNameSiblings(boolean value) {
+ this.jcrSameNameSiblings = value;
+ }
+
+ /**
+ * @param descriptor
+ */
+ public void setClassDescriptor(ClassDescriptor descriptor) {
+ this.classDescriptor = descriptor;
+ }
+
+ /**
+ * @return Returns the classDescriptor.
+ */
+ public ClassDescriptor getClassDescriptor() {
+ return classDescriptor;
+ }
+
+ public String toString() {
+
+ return "Bean Descriptor : " + this.fieldName;
+ }
+}
Propchange: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java?view=diff&rev=448311&r1=448310&r2=448311
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java Wed Sep 20 12:37:05 2006
@@ -1,568 +1,568 @@
-/*
- * Copyright 2000-2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.portals.graffito.jcr.mapper.model;
-
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.portals.graffito.jcr.exception.JcrMappingException;
-import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
-
-/**
- *
- * ClassDescriptor is used by the mapper to read general information on a class
- *
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
- * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
- */
-public class ClassDescriptor {
-
- private static final Log log = LogFactory.getLog(ClassDescriptor.class);
-
- private static final String NODETYPE_PER_HIERARCHY = "nodetypeperhierarchy";
- private static final String NODETYPE_PER_CONCRETECLASS = "nodetypeperconcreteclass";
-
- private MappingDescriptor mappingDescriptor;
- private ClassDescriptor superClassDescriptor;
- private Collection descendantClassDescriptors = new ArrayList();
-
- private String className;
- private String jcrNodeType;
- private String jcrSuperTypes;
- private String[] jcrMixinTypes = new String[0];
- private FieldDescriptor idFieldDescriptor;
- private FieldDescriptor pathFieldDescriptor;
-
- private Map fieldDescriptors = new HashMap();
- private Map beanDescriptors = new HashMap();
- private Map collectionDescriptors = new HashMap();
-
- private Map fieldNames = new HashMap();
-
- private String superClassName;
- private String extendsStrategy;
- private boolean isAbstract = false;
- private boolean hasDescendant = false;
- private boolean hasDiscriminator = true;
-
-
- private boolean isInterface=false;
- private List interfaces = new ArrayList();
-
- public void setAbstract(boolean flag) {
- this.isAbstract = flag;
- }
-
- public boolean isAbstract() {
- return this.isAbstract;
- }
-
- public void setInterface(boolean flag) {
- this.isInterface = flag;
- }
-
- public boolean isInterface() {
- return isInterface;
- }
-
- public boolean hasInterfaces()
- {
- return this.interfaces.size() > 0;
- }
-
- public void setDiscriminator(boolean flag)
- {
- this.hasDiscriminator = flag;
- }
-
- public boolean hasDiscriminator() {
- return this.hasDiscriminator;
- }
-
- public boolean usesNodeTypePerHierarchyStrategy() {
- return NODETYPE_PER_HIERARCHY.equals(this.extendsStrategy);
- }
-
- public boolean usesNodeTypePerConcreteClassStrategy() {
- return NODETYPE_PER_CONCRETECLASS.equals(this.extendsStrategy);
- }
- /**
- * @return Returns the className.
- */
- public String getClassName() {
- return className;
- }
-
- /**
- * @param className The className to set.
- */
- public void setClassName(String className) {
- this.className = className;
- }
-
- /**
- * @return Returns the jcrNodeType.
- */
- public String getJcrNodeType() {
- return jcrNodeType;
- }
-
- /**
- * @param jcrNodeType The jcrNodeType to set.
- */
- public void setJcrNodeType(String jcrNodeType) {
- this.jcrNodeType = jcrNodeType;
- }
-
- /**
- * Add a new FielDescriptor
- * @param fieldDescriptor the new field descriptor to add
- */
- public void addFieldDescriptor(FieldDescriptor fieldDescriptor) {
- fieldDescriptor.setClassDescriptor(this);
- if (fieldDescriptor.isId()) {
- this.idFieldDescriptor = fieldDescriptor;
- }
- if (fieldDescriptor.isPath()) {
- this.pathFieldDescriptor = fieldDescriptor;
- }
-
- fieldDescriptors.put(fieldDescriptor.getFieldName(), fieldDescriptor);
- fieldNames.put(fieldDescriptor.getFieldName(), fieldDescriptor.getJcrName());
- }
-
- public void addImplementDescriptor(ImplementDescriptor implementDescriptor)
- {
- interfaces.add(implementDescriptor.getInterfaceName());
- }
-
- /**
- * Get the FieldDescriptor to used for a specific java bean attribute
- * @param fieldName The java bean attribute name
- *
- * @return the {@link FieldDescriptor} found or null
- */
- public FieldDescriptor getFieldDescriptor(String fieldName) {
- return (FieldDescriptor) this.fieldDescriptors.get(fieldName);
- }
-
- /**
- *
- * @return all {@link FieldDescriptor} defined in this ClassDescriptor
- */
- public Collection getFieldDescriptors() {
- return this.fieldDescriptors.values();
- }
-
- /**
- * Add a new BeanDescriptor
- * @param beanDescriptor the new bean descriptor to add
- */
-
- public void addBeanDescriptor(BeanDescriptor beanDescriptor) {
- beanDescriptor.setClassDescriptor(this);
- beanDescriptors.put(beanDescriptor.getFieldName(), beanDescriptor);
- fieldNames.put(beanDescriptor.getFieldName(), beanDescriptor.getJcrName());
- }
-
- /**
- * Get the BeanDescriptor to used for a specific java bean attribute
- * @param fieldName The java bean attribute name
- *
- * @return the {@link BeanDescriptor} found or null
- */
- public BeanDescriptor getBeanDescriptor(String fieldName) {
- return (BeanDescriptor) this.beanDescriptors.get(fieldName);
- }
-
- /**
- * @return all {@link BeanDescriptor} defined in this ClassDescriptor
- */
- public Collection getBeanDescriptors() {
- return this.beanDescriptors.values();
- }
-
- /**
- * Add a new CollectionDescriptor
- * @param collectionDescriptor the new collection descriptor to add
- */
-
- public void addCollectionDescriptor(CollectionDescriptor collectionDescriptor) {
- collectionDescriptor.setClassDescriptor(this);
- collectionDescriptors.put(collectionDescriptor.getFieldName(), collectionDescriptor);
- fieldNames.put(collectionDescriptor.getFieldName(), collectionDescriptor.getJcrName());
- }
-
- /**
- * Get the CollectionDescriptor to used for a specific java bean attribute
- * @param fieldName The java bean attribute name
- *
- * @return the {@link CollectionDescriptor} found or null
- */
- public CollectionDescriptor getCollectionDescriptor(String fieldName) {
- return (CollectionDescriptor) this.collectionDescriptors.get(fieldName);
- }
-
- /**
- * @return all {@link BeanDescriptor} defined in this ClassDescriptor
- */
- public Collection getCollectionDescriptors() {
- return this.collectionDescriptors.values();
- }
-
- /**
- * @return the fieldDescriptor ID
- */
- public FieldDescriptor getIdFieldDescriptor() {
- return idFieldDescriptor;
- }
-
- /**
- * @return the fieldDescriptor path
- */
- public FieldDescriptor getPathFieldDescriptor() {
- if (null != this.pathFieldDescriptor) {
- return this.pathFieldDescriptor;
- }
-
- if (null != this.superClassDescriptor) {
- return this.superClassDescriptor.getPathFieldDescriptor();
- }
-
- return null;
- }
-
-
- /**
- * Check if this class has an ID
- * @return true if the class has an ID
- */
- public boolean hasIdField() {
- return (this.idFieldDescriptor != null && ! this.idFieldDescriptor.equals(""));
- }
-
- /**
- * Get the JCR name used for one of the object attributes
- * @param fieldName the object attribute name (can be an atomic field, bean field or a collection field)
- * @return the JCR name found
- */
- public String getJcrName(String fieldName) {
- String jcrName = (String) this.fieldNames.get(fieldName);
- if (this.isInterface && jcrName == null)
- {
- return this.getJcrNameFromDescendants(this, fieldName);
- }
-
- return jcrName;
- }
-
- private String getJcrNameFromDescendants(ClassDescriptor classDescriptor, String fieldName )
- {
- Iterator descendants = classDescriptor.getDescendantClassDescriptors().iterator();
- while (descendants.hasNext())
- {
- ClassDescriptor descendant = (ClassDescriptor) descendants.next();
- String jcrName = (String) descendant.fieldNames.get(fieldName);
- if(jcrName != null)
- {
- return jcrName;
- }
- return this.getJcrNameFromDescendants(descendant, fieldName);
- }
- return null;
-
-
- }
-
- public Map getFieldNames() {
- return this.fieldNames;
- }
-
- /** Get the JCR node super types.
- *
- * @return jcrSuperTypes
- */
- public String getJcrSuperTypes() {
- return jcrSuperTypes;
- }
-
- /** Setter for JCR super types.
- *
- * @param superTypes Comma separated list of JCR node super types
- */
- public void setJcrSuperTypes(String superTypes) {
- this.jcrSuperTypes = superTypes;
- }
-
- /**
- * Retrieve the mixin types.
- *
- * @return array of mixin types
- */
- public String[] getJcrMixinTypes() {
- return this.jcrMixinTypes;
- }
-
- /**
- * Sets a comma separated list of mixin types.
- *
- * @param mixinTypes command separated list of mixins
- */
- public void setJcrMixinTypes(String[] mixinTypes) {
- if (null != mixinTypes && mixinTypes.length == 1) {
- jcrMixinTypes = mixinTypes[0].split(" *, *");
- }
- }
-
- /**
- * @return Returns the mappingDescriptor.
- */
- public MappingDescriptor getMappingDescriptor() {
- return mappingDescriptor;
- }
-
- /**
- * @param mappingDescriptor The mappingDescriptor to set.
- */
- public void setMappingDescriptor(MappingDescriptor mappingDescriptor) {
- this.mappingDescriptor = mappingDescriptor;
- }
-
- /**
- * Revisit information in this descriptor and fills in more.
- */
- public void afterPropertiesSet() {
- validateClassName();
- validateBeanFields();
- lookupSuperDescriptor();
- lookupInheritanceSettings();
-// validateInheritanceSettings();
- }
-
- private void validateClassName() {
- try {
- ReflectionUtils.forName(this.className);
- } catch (JcrMappingException e) {
- throw new JcrMappingException("Class used in descriptor not found : " + className);
- }
- }
-
- private void validateBeanFields()
- {
- Iterator beanDescriptorIterator = beanDescriptors.values().iterator();
- while (beanDescriptorIterator.hasNext()) {
- BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
- if (beanDescriptor.isProxy() && beanDescriptor.isInline())
- {
- throw new JcrMappingException("Bean field can not be proxy and inline - class : " + this.className + " - bean field :" + beanDescriptor.getFieldName());
- }
-
- }
-
- }
-
- private void lookupSuperDescriptor() {
- if (null != superClassDescriptor) {
- this.hasDiscriminator = superClassDescriptor.hasDiscriminator();
- if (! this.isInterface)
- {
- this.fieldDescriptors = mergeFields(this.fieldDescriptors, this.superClassDescriptor.getFieldDescriptors());
- this.beanDescriptors = mergeBeans(this.beanDescriptors, this.superClassDescriptor.getBeanDescriptors());
- this.collectionDescriptors = mergeCollections(this.collectionDescriptors, this.superClassDescriptor.getCollectionDescriptors());
- this.fieldNames.putAll(this.superClassDescriptor.getFieldNames());
- }
-
- }
- }
-
- private void lookupInheritanceSettings() {
- if ((null != this.superClassDescriptor) || (this.hasDescendants()) || this.hasInterfaces()) {
- if (this.hasDiscriminator()) {
- this.extendsStrategy = NODETYPE_PER_HIERARCHY;
- }
- else {
- this.extendsStrategy = NODETYPE_PER_CONCRETECLASS;
- }
- }
- }
-
-
- /**
- * @return return the super class name if defined in mapping, or
- * <tt>null</tt> if not set
- */
- public String getExtend() {
- return this.superClassName;
- }
-
- /**
- * @param className
- */
- public void setExtend(String className) {
- this.superClassName = className;
- }
-
- /**
- * @return Returns the superClassDescriptor.
- */
- public ClassDescriptor getSuperClassDescriptor() {
- return superClassDescriptor;
- }
-
- public Collection getDescendantClassDescriptors() {
- return this.descendantClassDescriptors;
- }
-
- /**
- * If the node type per concrete class strategy is used, we need to find a descendant class descriptor assigned to a node type
- * This method is not used in other situation.
- *
- * @param nodeType the node type for which the classdescriptor is required
- * @return the classdescriptor found or null
- *
- * @todo : maybe we have to review this implementation to have better performance.
- */
- public ClassDescriptor getDescendantClassDescriptor(String nodeType) {
- Iterator iterator = this.descendantClassDescriptors.iterator();
- while (iterator.hasNext()) {
- ClassDescriptor descendantClassDescriptor = (ClassDescriptor) iterator.next();
-
- if (descendantClassDescriptor.getJcrNodeType().equals(nodeType)) {
- return descendantClassDescriptor;
- }
-
- if (descendantClassDescriptor.hasDescendants()) {
- ClassDescriptor classDescriptor = descendantClassDescriptor.getDescendantClassDescriptor(nodeType);
- if (classDescriptor != null) {
- return classDescriptor;
- }
- }
- }
- return null;
- }
-
- public void addDescendantClassDescriptor(ClassDescriptor classDescriptor) {
- this.descendantClassDescriptors.add(classDescriptor);
- this.hasDescendant = true;
- }
-
- public boolean hasDescendants() {
- return this.hasDescendant;
- }
-
- /**
- * @param superClassDescriptor The superClassDescriptor to set.
- */
- public void setSuperClassDescriptor(ClassDescriptor superClassDescriptor) {
- this.superClassDescriptor= superClassDescriptor;
- superClassDescriptor.addDescendantClassDescriptor(this);
- }
-
-
- public Collection getImplements()
- {
- return interfaces;
- }
-
- private Map mergeFields(Map existing, Collection superSource) {
- if (null == superSource) {
- return existing;
- }
-
- Map merged = new HashMap(existing);
- for(Iterator it = superSource.iterator(); it.hasNext();) {
- FieldDescriptor fieldDescriptor = (FieldDescriptor) it.next();
- if (!merged.containsKey(fieldDescriptor.getFieldName())) {
- merged.put(fieldDescriptor.getFieldName(), fieldDescriptor);
- }
-// else {
-// log.warn("Field name conflict in " + this.className + " - field : " +fieldDescriptor.getFieldName() + " - this field name is also defined in the ancestor class : " + this.getExtend());
-// }
- }
-
- return merged;
- }
-
-
- private Map mergeBeans(Map existing, Collection superSource) {
- if (null == superSource) {
- return existing;
- }
-
- Map merged = new HashMap(existing);
- for(Iterator it = superSource.iterator(); it.hasNext();) {
- BeanDescriptor beanDescriptor = (BeanDescriptor) it.next();
- if (!merged.containsKey(beanDescriptor.getFieldName())) {
- merged.put(beanDescriptor.getFieldName(), beanDescriptor);
- }
-// else {
-// log.warn("Bean name conflict in " + this.className + " - field : " +beanDescriptor.getFieldName() + " - this field name is also defined in the ancestor class : " + this.getExtend());
-// }
- }
-
- return merged;
- }
-
- private Map mergeCollections(Map existing, Collection superSource) {
- if (null == superSource) {
- return existing;
- }
-
- Map merged = new HashMap(existing);
- for(Iterator it = superSource.iterator(); it.hasNext();) {
- CollectionDescriptor collectionDescriptor = (CollectionDescriptor) it.next();
- if (!merged.containsKey(collectionDescriptor.getFieldName())) {
- merged.put(collectionDescriptor.getFieldName(), collectionDescriptor);
- }
-// else {
-// log.warn("Collection name conflict in " + this.className + " - field : " +collectionDescriptor.getFieldName() + " - this field name is also defined in the ancestor class : " + this.getExtend());
-// }
- }
-
- return merged;
- }
-
-
-// private List mergeInterfaces(List existing, Collection superSource) {
-// if (null == superSource) {
-// return existing;
-// }
-//
-// ArrayList merged = new ArrayList(existing);
-// for (Iterator it = superSource.iterator(); it.hasNext();)
-// {
-// String interfaceName = (String) it.next();
-// if (! merged.contains(interfaceName))
-// {
-// merged.add(interfaceName);
-// }
-// }
-//
-// return merged;
-// }
-
-
- public String toString() {
- return "Class Descriptor : " + this.getClassName();
- }
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.mapper.model;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
+
+/**
+ *
+ * ClassDescriptor is used by the mapper to read general information on a class
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ */
+public class ClassDescriptor {
+
+ private static final Log log = LogFactory.getLog(ClassDescriptor.class);
+
+ private static final String NODETYPE_PER_HIERARCHY = "nodetypeperhierarchy";
+ private static final String NODETYPE_PER_CONCRETECLASS = "nodetypeperconcreteclass";
+
+ private MappingDescriptor mappingDescriptor;
+ private ClassDescriptor superClassDescriptor;
+ private Collection descendantClassDescriptors = new ArrayList();
+
+ private String className;
+ private String jcrNodeType;
+ private String jcrSuperTypes;
+ private String[] jcrMixinTypes = new String[0];
+ private FieldDescriptor idFieldDescriptor;
+ private FieldDescriptor pathFieldDescriptor;
+
+ private Map fieldDescriptors = new HashMap();
+ private Map beanDescriptors = new HashMap();
+ private Map collectionDescriptors = new HashMap();
+
+ private Map fieldNames = new HashMap();
+
+ private String superClassName;
+ private String extendsStrategy;
+ private boolean isAbstract = false;
+ private boolean hasDescendant = false;
+ private boolean hasDiscriminator = true;
+
+
+ private boolean isInterface=false;
+ private List interfaces = new ArrayList();
+
+ public void setAbstract(boolean flag) {
+ this.isAbstract = flag;
+ }
+
+ public boolean isAbstract() {
+ return this.isAbstract;
+ }
+
+ public void setInterface(boolean flag) {
+ this.isInterface = flag;
+ }
+
+ public boolean isInterface() {
+ return isInterface;
+ }
+
+ public boolean hasInterfaces()
+ {
+ return this.interfaces.size() > 0;
+ }
+
+ public void setDiscriminator(boolean flag)
+ {
+ this.hasDiscriminator = flag;
+ }
+
+ public boolean hasDiscriminator() {
+ return this.hasDiscriminator;
+ }
+
+ public boolean usesNodeTypePerHierarchyStrategy() {
+ return NODETYPE_PER_HIERARCHY.equals(this.extendsStrategy);
+ }
+
+ public boolean usesNodeTypePerConcreteClassStrategy() {
+ return NODETYPE_PER_CONCRETECLASS.equals(this.extendsStrategy);
+ }
+ /**
+ * @return Returns the className.
+ */
+ public String getClassName() {
+ return className;
+ }
+
+ /**
+ * @param className The className to set.
+ */
+ public void setClassName(String className) {
+ this.className = className;
+ }
+
+ /**
+ * @return Returns the jcrNodeType.
+ */
+ public String getJcrNodeType() {
+ return jcrNodeType;
+ }
+
+ /**
+ * @param jcrNodeType The jcrNodeType to set.
+ */
+ public void setJcrNodeType(String jcrNodeType) {
+ this.jcrNodeType = jcrNodeType;
+ }
+
+ /**
+ * Add a new FielDescriptor
+ * @param fieldDescriptor the new field descriptor to add
+ */
+ public void addFieldDescriptor(FieldDescriptor fieldDescriptor) {
+ fieldDescriptor.setClassDescriptor(this);
+ if (fieldDescriptor.isId()) {
+ this.idFieldDescriptor = fieldDescriptor;
+ }
+ if (fieldDescriptor.isPath()) {
+ this.pathFieldDescriptor = fieldDescriptor;
+ }
+
+ fieldDescriptors.put(fieldDescriptor.getFieldName(), fieldDescriptor);
+ fieldNames.put(fieldDescriptor.getFieldName(), fieldDescriptor.getJcrName());
+ }
+
+ public void addImplementDescriptor(ImplementDescriptor implementDescriptor)
+ {
+ interfaces.add(implementDescriptor.getInterfaceName());
+ }
+
+ /**
+ * Get the FieldDescriptor to used for a specific java bean attribute
+ * @param fieldName The java bean attribute name
+ *
+ * @return the {@link FieldDescriptor} found or null
+ */
+ public FieldDescriptor getFieldDescriptor(String fieldName) {
+ return (FieldDescriptor) this.fieldDescriptors.get(fieldName);
+ }
+
+ /**
+ *
+ * @return all {@link FieldDescriptor} defined in this ClassDescriptor
+ */
+ public Collection getFieldDescriptors() {
+ return this.fieldDescriptors.values();
+ }
+
+ /**
+ * Add a new BeanDescriptor
+ * @param beanDescriptor the new bean descriptor to add
+ */
+
+ public void addBeanDescriptor(BeanDescriptor beanDescriptor) {
+ beanDescriptor.setClassDescriptor(this);
+ beanDescriptors.put(beanDescriptor.getFieldName(), beanDescriptor);
+ fieldNames.put(beanDescriptor.getFieldName(), beanDescriptor.getJcrName());
+ }
+
+ /**
+ * Get the BeanDescriptor to used for a specific java bean attribute
+ * @param fieldName The java bean attribute name
+ *
+ * @return the {@link BeanDescriptor} found or null
+ */
+ public BeanDescriptor getBeanDescriptor(String fieldName) {
+ return (BeanDescriptor) this.beanDescriptors.get(fieldName);
+ }
+
+ /**
+ * @return all {@link BeanDescriptor} defined in this ClassDescriptor
+ */
+ public Collection getBeanDescriptors() {
+ return this.beanDescriptors.values();
+ }
+
+ /**
+ * Add a new CollectionDescriptor
+ * @param collectionDescriptor the new collection descriptor to add
+ */
+
+ public void addCollectionDescriptor(CollectionDescriptor collectionDescriptor) {
+ collectionDescriptor.setClassDescriptor(this);
+ collectionDescriptors.put(collectionDescriptor.getFieldName(), collectionDescriptor);
+ fieldNames.put(collectionDescriptor.getFieldName(), collectionDescriptor.getJcrName());
+ }
+
+ /**
+ * Get the CollectionDescriptor to used for a specific java bean attribute
+ * @param fieldName The java bean attribute name
+ *
+ * @return the {@link CollectionDescriptor} found or null
+ */
+ public CollectionDescriptor getCollectionDescriptor(String fieldName) {
+ return (CollectionDescriptor) this.collectionDescriptors.get(fieldName);
+ }
+
+ /**
+ * @return all {@link BeanDescriptor} defined in this ClassDescriptor
+ */
+ public Collection getCollectionDescriptors() {
+ return this.collectionDescriptors.values();
+ }
+
+ /**
+ * @return the fieldDescriptor ID
+ */
+ public FieldDescriptor getIdFieldDescriptor() {
+ return idFieldDescriptor;
+ }
+
+ /**
+ * @return the fieldDescriptor path
+ */
+ public FieldDescriptor getPathFieldDescriptor() {
+ if (null != this.pathFieldDescriptor) {
+ return this.pathFieldDescriptor;
+ }
+
+ if (null != this.superClassDescriptor) {
+ return this.superClassDescriptor.getPathFieldDescriptor();
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Check if this class has an ID
+ * @return true if the class has an ID
+ */
+ public boolean hasIdField() {
+ return (this.idFieldDescriptor != null && ! this.idFieldDescriptor.equals(""));
+ }
+
+ /**
+ * Get the JCR name used for one of the object attributes
+ * @param fieldName the object attribute name (can be an atomic field, bean field or a collection field)
+ * @return the JCR name found
+ */
+ public String getJcrName(String fieldName) {
+ String jcrName = (String) this.fieldNames.get(fieldName);
+ if (this.isInterface && jcrName == null)
+ {
+ return this.getJcrNameFromDescendants(this, fieldName);
+ }
+
+ return jcrName;
+ }
+
+ private String getJcrNameFromDescendants(ClassDescriptor classDescriptor, String fieldName )
+ {
+ Iterator descendants = classDescriptor.getDescendantClassDescriptors().iterator();
+ while (descendants.hasNext())
+ {
+ ClassDescriptor descendant = (ClassDescriptor) descendants.next();
+ String jcrName = (String) descendant.fieldNames.get(fieldName);
+ if(jcrName != null)
+ {
+ return jcrName;
+ }
+ return this.getJcrNameFromDescendants(descendant, fieldName);
+ }
+ return null;
+
+
+ }
+
+ public Map getFieldNames() {
+ return this.fieldNames;
+ }
+
+ /** Get the JCR node super types.
+ *
+ * @return jcrSuperTypes
+ */
+ public String getJcrSuperTypes() {
+ return jcrSuperTypes;
+ }
+
+ /** Setter for JCR super types.
+ *
+ * @param superTypes Comma separated list of JCR node super types
+ */
+ public void setJcrSuperTypes(String superTypes) {
+ this.jcrSuperTypes = superTypes;
+ }
+
+ /**
+ * Retrieve the mixin types.
+ *
+ * @return array of mixin types
+ */
+ public String[] getJcrMixinTypes() {
+ return this.jcrMixinTypes;
+ }
+
+ /**
+ * Sets a comma separated list of mixin types.
+ *
+ * @param mixinTypes command separated list of mixins
+ */
+ public void setJcrMixinTypes(String[] mixinTypes) {
+ if (null != mixinTypes && mixinTypes.length == 1) {
+ jcrMixinTypes = mixinTypes[0].split(" *, *");
+ }
+ }
+
+ /**
+ * @return Returns the mappingDescriptor.
+ */
+ public MappingDescriptor getMappingDescriptor() {
+ return mappingDescriptor;
+ }
+
+ /**
+ * @param mappingDescriptor The mappingDescriptor to set.
+ */
+ public void setMappingDescriptor(MappingDescriptor mappingDescriptor) {
+ this.mappingDescriptor = mappingDescriptor;
+ }
+
+ /**
+ * Revisit information in this descriptor and fills in more.
+ */
+ public void afterPropertiesSet() {
+ validateClassName();
+ validateBeanFields();
+ lookupSuperDescriptor();
+ lookupInheritanceSettings();
+// validateInheritanceSettings();
+ }
+
+ private void validateClassName() {
+ try {
+ ReflectionUtils.forName(this.className);
+ } catch (JcrMappingException e) {
+ throw new JcrMappingException("Class used in descriptor not found : " + className);
+ }
+ }
+
+ private void validateBeanFields()
+ {
+ Iterator beanDescriptorIterator = beanDescriptors.values().iterator();
+ while (beanDescriptorIterator.hasNext()) {
+ BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
+ if (beanDescriptor.isProxy() && beanDescriptor.isInline())
+ {
+ throw new JcrMappingException("Bean field can not be proxy and inline - class : " + this.className + " - bean field :" + beanDescriptor.getFieldName());
+ }
+
+ }
+
+ }
+
+ private void lookupSuperDescriptor() {
+ if (null != superClassDescriptor) {
+ this.hasDiscriminator = superClassDescriptor.hasDiscriminator();
+ if (! this.isInterface)
+ {
+ this.fieldDescriptors = mergeFields(this.fieldDescriptors, this.superClassDescriptor.getFieldDescriptors());
+ this.beanDescriptors = mergeBeans(this.beanDescriptors, this.superClassDescriptor.getBeanDescriptors());
+ this.collectionDescriptors = mergeCollections(this.collectionDescriptors, this.superClassDescriptor.getCollectionDescriptors());
+ this.fieldNames.putAll(this.superClassDescriptor.getFieldNames());
+ }
+
+ }
+ }
+
+ private void lookupInheritanceSettings() {
+ if ((null != this.superClassDescriptor) || (this.hasDescendants()) || this.hasInterfaces()) {
+ if (this.hasDiscriminator()) {
+ this.extendsStrategy = NODETYPE_PER_HIERARCHY;
+ }
+ else {
+ this.extendsStrategy = NODETYPE_PER_CONCRETECLASS;
+ }
+ }
+ }
+
+
+ /**
+ * @return return the super class name if defined in mapping, or
+ * <tt>null</tt> if not set
+ */
+ public String getExtend() {
+ return this.superClassName;
+ }
+
+ /**
+ * @param className
+ */
+ public void setExtend(String className) {
+ this.superClassName = className;
+ }
+
+ /**
+ * @return Returns the superClassDescriptor.
+ */
+ public ClassDescriptor getSuperClassDescriptor() {
+ return superClassDescriptor;
+ }
+
+ public Collection getDescendantClassDescriptors() {
+ return this.descendantClassDescriptors;
+ }
+
+ /**
+ * If the node type per concrete class strategy is used, we need to find a descendant class descriptor assigned to a node type
+ * This method is not used in other situation.
+ *
+ * @param nodeType the node type for which the classdescriptor is required
+ * @return the classdescriptor found or null
+ *
+ * @todo : maybe we have to review this implementation to have better performance.
+ */
+ public ClassDescriptor getDescendantClassDescriptor(String nodeType) {
+ Iterator iterator = this.descendantClassDescriptors.iterator();
+ while (iterator.hasNext()) {
+ ClassDescriptor descendantClassDescriptor = (ClassDescriptor) iterator.next();
+
+ if (descendantClassDescriptor.getJcrNodeType().equals(nodeType)) {
+ return descendantClassDescriptor;
+ }
+
+ if (descendantClassDescriptor.hasDescendants()) {
+ ClassDescriptor classDescriptor = descendantClassDescriptor.getDescendantClassDescriptor(nodeType);
+ if (classDescriptor != null) {
+ return classDescriptor;
+ }
+ }
+ }
+ return null;
+ }
+
+ public void addDescendantClassDescriptor(ClassDescriptor classDescriptor) {
+ this.descendantClassDescriptors.add(classDescriptor);
+ this.hasDescendant = true;
+ }
+
+ public boolean hasDescendants() {
+ return this.hasDescendant;
+ }
+
+ /**
+ * @param superClassDescriptor The superClassDescriptor to set.
+ */
+ public void setSuperClassDescriptor(ClassDescriptor superClassDescriptor) {
+ this.superClassDescriptor= superClassDescriptor;
+ superClassDescriptor.addDescendantClassDescriptor(this);
+ }
+
+
+ public Collection getImplements()
+ {
+ return interfaces;
+ }
+
+ private Map mergeFields(Map existing, Collection superSource) {
+ if (null == superSource) {
+ return existing;
+ }
+
+ Map merged = new HashMap(existing);
+ for(Iterator it = superSource.iterator(); it.hasNext();) {
+ FieldDescriptor fieldDescriptor = (FieldDescriptor) it.next();
+ if (!merged.containsKey(fieldDescriptor.getFieldName())) {
+ merged.put(fieldDescriptor.getFieldName(), fieldDescriptor);
+ }
+// else {
+// log.warn("Field name conflict in " + this.className + " - field : " +fieldDescriptor.getFieldName() + " - this field name is also defined in the ancestor class : " + this.getExtend());
+// }
+ }
+
+ return merged;
+ }
+
+
+ private Map mergeBeans(Map existing, Collection superSource) {
+ if (null == superSource) {
+ return existing;
+ }
+
+ Map merged = new HashMap(existing);
+ for(Iterator it = superSource.iterator(); it.hasNext();) {
+ BeanDescriptor beanDescriptor = (BeanDescriptor) it.next();
+ if (!merged.containsKey(beanDescriptor.getFieldName())) {
+ merged.put(beanDescriptor.getFieldName(), beanDescriptor);
+ }
+// else {
+// log.warn("Bean name conflict in " + this.className + " - field : " +beanDescriptor.getFieldName() + " - this field name is also defined in the ancestor class : " + this.getExtend());
+// }
+ }
+
+ return merged;
+ }
+
+ private Map mergeCollections(Map existing, Collection superSource) {
+ if (null == superSource) {
+ return existing;
+ }
+
+ Map merged = new HashMap(existing);
+ for(Iterator it = superSource.iterator(); it.hasNext();) {
+ CollectionDescriptor collectionDescriptor = (CollectionDescriptor) it.next();
+ if (!merged.containsKey(collectionDescriptor.getFieldName())) {
+ merged.put(collectionDescriptor.getFieldName(), collectionDescriptor);
+ }
+// else {
+// log.warn("Collection name conflict in " + this.className + " - field : " +collectionDescriptor.getFieldName() + " - this field name is also defined in the ancestor class : " + this.getExtend());
+// }
+ }
+
+ return merged;
+ }
+
+
+// private List mergeInterfaces(List existing, Collection superSource) {
+// if (null == superSource) {
+// return existing;
+// }
+//
+// ArrayList merged = new ArrayList(existing);
+// for (Iterator it = superSource.iterator(); it.hasNext();)
+// {
+// String interfaceName = (String) it.next();
+// if (! merged.contains(interfaceName))
+// {
+// merged.add(interfaceName);
+// }
+// }
+//
+// return merged;
+// }
+
+
+ public String toString() {
+ return "Class Descriptor : " + this.getClassName();
+ }
}
Propchange: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
------------------------------------------------------------------------------
svn:eol-style = native