mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
- Incorporate JCR project into Repository project
- Single configuration entry point for JCR and non-JCR clients (i.e. application-context.xml) - Addition of build-war, incremental-war build targets (no deploy) - Remove build of JCR TCK war file by default git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2777 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
139
source/java/org/alfresco/jcr/dictionary/ClassMap.java
Normal file
139
source/java/org/alfresco/jcr/dictionary/ClassMap.java
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.jcr.dictionary;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jcr.RepositoryException;
|
||||
|
||||
import org.alfresco.jcr.session.SessionImpl;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Responsible for mapping Alfresco Classes to JCR Types / Mixins and vice versa.
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class ClassMap
|
||||
{
|
||||
/** Map of Alfresco Class to JCR Class */
|
||||
private static Map<QName, QName> JCRToAlfresco = new HashMap<QName, QName>();
|
||||
static
|
||||
{
|
||||
JCRToAlfresco.put(NodeTypeImpl.MIX_REFERENCEABLE, ContentModel.ASPECT_REFERENCEABLE);
|
||||
JCRToAlfresco.put(NodeTypeImpl.MIX_LOCKABLE, ContentModel.ASPECT_LOCKABLE);
|
||||
JCRToAlfresco.put(NodeTypeImpl.MIX_VERSIONABLE, ContentModel.ASPECT_VERSIONABLE);
|
||||
}
|
||||
|
||||
/** Map of JCR Class to Alfresco Class */
|
||||
private static Map<QName, QName> AlfrescoToJCR = new HashMap<QName, QName>();
|
||||
static
|
||||
{
|
||||
AlfrescoToJCR.put(ContentModel.ASPECT_REFERENCEABLE, NodeTypeImpl.MIX_REFERENCEABLE);
|
||||
AlfrescoToJCR.put(ContentModel.ASPECT_LOCKABLE, NodeTypeImpl.MIX_LOCKABLE);
|
||||
AlfrescoToJCR.put(ContentModel.ASPECT_VERSIONABLE, NodeTypeImpl.MIX_VERSIONABLE);
|
||||
}
|
||||
|
||||
/** Map of JCR to Alfresco "Add Aspect" Behaviours */
|
||||
private static Map<QName, AddMixin> addMixin = new HashMap<QName, AddMixin>();
|
||||
static
|
||||
{
|
||||
addMixin.put(ContentModel.ASPECT_VERSIONABLE, new VersionableMixin());
|
||||
}
|
||||
|
||||
/** Map of JCR to Alfresco "Remove Aspect" Behaviours */
|
||||
private static Map<QName, RemoveMixin> removeMixin = new HashMap<QName, RemoveMixin>();
|
||||
static
|
||||
{
|
||||
removeMixin.put(ContentModel.ASPECT_VERSIONABLE, new VersionableMixin());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert an Alfresco Class to a JCR Type
|
||||
*
|
||||
* @param jcrType JCR Type
|
||||
* @return Alfresco Class
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
public static QName convertTypeToClass(QName jcrType)
|
||||
{
|
||||
return JCRToAlfresco.get(jcrType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an Alfresco Class to a JCR Type
|
||||
*
|
||||
* @param alfrescoClass Alfresco Class
|
||||
* @return JCR Type
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
public static QName convertClassToType(QName alfrescoClass)
|
||||
{
|
||||
return JCRToAlfresco.get(alfrescoClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get 'Add Mixin' JCR behaviour
|
||||
*
|
||||
* @param alfrescoClass
|
||||
* @return AddMixin behaviour
|
||||
*/
|
||||
public static AddMixin getAddMixin(QName alfrescoClass)
|
||||
{
|
||||
return addMixin.get(alfrescoClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get 'Remove Mixin' JCR behaviour
|
||||
*
|
||||
* @param alfrescoClass
|
||||
* @return RemoveMixin behaviour
|
||||
*/
|
||||
public static RemoveMixin getRemoveMixin(QName alfrescoClass)
|
||||
{
|
||||
return removeMixin.get(alfrescoClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Mixin Behaviour
|
||||
*
|
||||
* Encapsulates mapping of JCR behaviour to Alfresco
|
||||
*/
|
||||
public interface AddMixin
|
||||
{
|
||||
public Map<QName, Serializable> preAddMixin(SessionImpl session, NodeRef nodeRef);
|
||||
public void postAddMixin(SessionImpl session, NodeRef nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Mixin Behaviour
|
||||
*
|
||||
* Encapsulates mapping of JCR behaviour to Alfresco
|
||||
*/
|
||||
public interface RemoveMixin
|
||||
{
|
||||
public void preRemoveMixin(SessionImpl session, NodeRef nodeRef);
|
||||
public void postRemoveMixin(SessionImpl session, NodeRef nodeRef);
|
||||
}
|
||||
|
||||
}
|
108
source/java/org/alfresco/jcr/dictionary/DataTypeMap.java
Normal file
108
source/java/org/alfresco/jcr/dictionary/DataTypeMap.java
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.jcr.dictionary;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jcr.PropertyType;
|
||||
import javax.jcr.RepositoryException;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Responsible for mapping Alfresco Data Types to JCR Property Types and vice versa.
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class DataTypeMap
|
||||
{
|
||||
|
||||
/** Map of Alfresco Data Type to JCR Property Type */
|
||||
private static Map<QName, Integer> dataTypeToPropertyType = new HashMap<QName, Integer>();
|
||||
static
|
||||
{
|
||||
dataTypeToPropertyType.put(DataTypeDefinition.TEXT, PropertyType.STRING);
|
||||
dataTypeToPropertyType.put(DataTypeDefinition.CONTENT, PropertyType.BINARY);
|
||||
dataTypeToPropertyType.put(DataTypeDefinition.INT, PropertyType.LONG);
|
||||
dataTypeToPropertyType.put(DataTypeDefinition.LONG, PropertyType.LONG);
|
||||
dataTypeToPropertyType.put(DataTypeDefinition.FLOAT, PropertyType.DOUBLE);
|
||||
dataTypeToPropertyType.put(DataTypeDefinition.DOUBLE, PropertyType.DOUBLE);
|
||||
dataTypeToPropertyType.put(DataTypeDefinition.DATE, PropertyType.DATE);
|
||||
dataTypeToPropertyType.put(DataTypeDefinition.DATETIME, PropertyType.DATE);
|
||||
dataTypeToPropertyType.put(DataTypeDefinition.BOOLEAN, PropertyType.BOOLEAN);
|
||||
dataTypeToPropertyType.put(DataTypeDefinition.QNAME, PropertyType.NAME);
|
||||
dataTypeToPropertyType.put(DataTypeDefinition.CATEGORY, PropertyType.STRING); // TODO: Check this mapping
|
||||
dataTypeToPropertyType.put(DataTypeDefinition.NODE_REF, PropertyType.REFERENCE);
|
||||
dataTypeToPropertyType.put(DataTypeDefinition.PATH, PropertyType.PATH);
|
||||
dataTypeToPropertyType.put(DataTypeDefinition.ANY, PropertyType.UNDEFINED);
|
||||
}
|
||||
|
||||
/** Map of JCR Property Type to Alfresco Data Type */
|
||||
private static Map<Integer, QName> propertyTypeToDataType = new HashMap<Integer, QName>();
|
||||
static
|
||||
{
|
||||
propertyTypeToDataType.put(PropertyType.STRING, DataTypeDefinition.TEXT);
|
||||
propertyTypeToDataType.put(PropertyType.BINARY, DataTypeDefinition.CONTENT);
|
||||
propertyTypeToDataType.put(PropertyType.LONG, DataTypeDefinition.LONG);
|
||||
propertyTypeToDataType.put(PropertyType.DOUBLE, DataTypeDefinition.DOUBLE);
|
||||
propertyTypeToDataType.put(PropertyType.DATE, DataTypeDefinition.DATETIME);
|
||||
propertyTypeToDataType.put(PropertyType.BOOLEAN, DataTypeDefinition.BOOLEAN);
|
||||
propertyTypeToDataType.put(PropertyType.NAME, DataTypeDefinition.QNAME);
|
||||
propertyTypeToDataType.put(PropertyType.REFERENCE, DataTypeDefinition.NODE_REF);
|
||||
propertyTypeToDataType.put(PropertyType.PATH, DataTypeDefinition.PATH);
|
||||
propertyTypeToDataType.put(PropertyType.UNDEFINED, DataTypeDefinition.ANY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an Alfresco Data Type to a JCR Property Type
|
||||
*
|
||||
* @param datatype alfresco data type
|
||||
* @return JCR property type
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
public static int convertDataTypeToPropertyType(QName datatype)
|
||||
{
|
||||
Integer propertyType = dataTypeToPropertyType.get(datatype);
|
||||
if (propertyType == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Cannot map Alfresco data type " + datatype + " to JCR property type.");
|
||||
}
|
||||
return propertyType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a JCR Property Type to an Alfresco Data Type
|
||||
*
|
||||
* @param propertyType JCR property type
|
||||
* @return alfresco data type
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
public static QName convertPropertyTypeToDataType(int propertyType)
|
||||
{
|
||||
QName type = propertyTypeToDataType.get(propertyType);
|
||||
if (type == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Cannot map JCR property type " + propertyType + " to Alfresco data type.");
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
40
source/java/org/alfresco/jcr/dictionary/JCRNamespace.java
Normal file
40
source/java/org/alfresco/jcr/dictionary/JCRNamespace.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.jcr.dictionary;
|
||||
|
||||
|
||||
/**
|
||||
* JCR Namespace definitions
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class JCRNamespace
|
||||
{
|
||||
public static String XML_PREFIX = "xml";
|
||||
|
||||
public static String JCR_URI = "http://www.jcp.org/jcr/1.0";
|
||||
public static String JCR_PREFIX = "jcr";
|
||||
|
||||
public static String NT_URI = "http://www.jcp.org/jcr/nt/1.0";
|
||||
public static String NT_PREFIX = "nt";
|
||||
|
||||
public static String MIX_URI = "http://www.jcp.org/jcr/mix/1.0";
|
||||
public static String MIX_PREFIX = "mix";
|
||||
|
||||
public static String SV_URI = "http://www.jcp.org/jcr/sv/1.0";
|
||||
public static String SV_PREFIX = "sv";
|
||||
}
|
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.jcr.dictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.namespace.NamespaceException;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
|
||||
|
||||
/**
|
||||
* JCR Namespace Resolver
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class JCRNamespacePrefixResolver implements NamespaceService
|
||||
{
|
||||
// delegate
|
||||
private NamespacePrefixResolver delegate;
|
||||
|
||||
// prefix -> uri
|
||||
private Map<String, String> prefixes = new HashMap<String, String>();
|
||||
|
||||
// uri -> prefix
|
||||
private Map<String, String> uris = new HashMap<String, String>();
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param delegate namespace delegate
|
||||
*/
|
||||
public JCRNamespacePrefixResolver(NamespacePrefixResolver delegate)
|
||||
{
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.namespace.NamespacePrefixResolver#getPrefixes(java.lang.String)
|
||||
*/
|
||||
public Collection<String> getPrefixes(String namespaceURI) throws NamespaceException
|
||||
{
|
||||
String prefix = uris.get(namespaceURI);
|
||||
if (prefix == null)
|
||||
{
|
||||
return delegate.getPrefixes(namespaceURI);
|
||||
}
|
||||
List<String> prefixes = new ArrayList<String>();
|
||||
prefixes.add(prefix);
|
||||
return prefixes;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.namespace.NamespacePrefixResolver#getPrefixes()
|
||||
*/
|
||||
public Collection<String> getPrefixes()
|
||||
{
|
||||
List<String> prefixes = new ArrayList<String>();
|
||||
Collection<String> uris = getURIs();
|
||||
for (String uri : uris)
|
||||
{
|
||||
Collection<String> uriPrefixes = getPrefixes(uri);
|
||||
prefixes.addAll(uriPrefixes);
|
||||
}
|
||||
return prefixes;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.namespace.NamespaceService#registerNamespace(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void registerNamespace(String prefix, String uri)
|
||||
{
|
||||
//
|
||||
// Check re-mapping according to JCR specification
|
||||
//
|
||||
|
||||
// Cannot map any prefix that starts with xml
|
||||
if (prefix.toLowerCase().startsWith(JCRNamespace.XML_PREFIX))
|
||||
{
|
||||
throw new NamespaceException("Cannot map prefix " + prefix + " as it is reserved");
|
||||
}
|
||||
|
||||
// Cannot remap a prefix that is already assigned to a uri
|
||||
String existingUri = delegate.getNamespaceURI(prefix);
|
||||
if (existingUri != null)
|
||||
{
|
||||
throw new NamespaceException("Cannot map prefix " + prefix + " as it is already assigned to uri " + existingUri);
|
||||
}
|
||||
|
||||
// Cannot map a prefix to a non-existent uri
|
||||
Collection<String> existingURIs = delegate.getURIs();
|
||||
if (existingURIs.contains(uri) == false)
|
||||
{
|
||||
throw new NamespaceException("Cannot map prefix " + prefix + " to uri " + uri + " which does not exist");
|
||||
}
|
||||
|
||||
prefixes.put(prefix, uri);
|
||||
uris.put(uri, prefix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.namespace.NamespaceService#unregisterNamespace(java.lang.String)
|
||||
*/
|
||||
public void unregisterNamespace(String prefix)
|
||||
{
|
||||
String uri = prefixes.get(prefix);
|
||||
if (uri != null)
|
||||
{
|
||||
uris.remove(uri);
|
||||
}
|
||||
prefixes.remove(prefix);
|
||||
}
|
||||
|
||||
public String getNamespaceURI(String prefix) throws NamespaceException
|
||||
{
|
||||
String uri = prefixes.get(prefix);
|
||||
if (uri == null)
|
||||
{
|
||||
return delegate.getNamespaceURI(prefix);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.namespace.NamespacePrefixResolver#getURIs()
|
||||
*/
|
||||
public Collection<String> getURIs()
|
||||
{
|
||||
return delegate.getURIs();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.jcr.dictionary;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.jcr.AccessDeniedException;
|
||||
import javax.jcr.NamespaceException;
|
||||
import javax.jcr.NamespaceRegistry;
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.UnsupportedRepositoryOperationException;
|
||||
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
|
||||
|
||||
/**
|
||||
* Alfresco implementation of a JCR Namespace registry
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class NamespaceRegistryImpl implements NamespaceRegistry
|
||||
{
|
||||
|
||||
private boolean allowRegistration;
|
||||
private NamespaceService namespaceService;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param namespaceService namespace service
|
||||
*/
|
||||
public NamespaceRegistryImpl(boolean allowRegistraton, NamespaceService namespaceService)
|
||||
{
|
||||
this.allowRegistration = allowRegistraton;
|
||||
this.namespaceService = namespaceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the namespace prefix resolver
|
||||
*
|
||||
* @return the namespace prefix resolver
|
||||
*/
|
||||
public NamespaceService getNamespaceService()
|
||||
{
|
||||
return this.namespaceService;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.NamespaceRegistry#registerNamespace(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void registerNamespace(String prefix, String uri) throws NamespaceException, UnsupportedRepositoryOperationException, AccessDeniedException, RepositoryException
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!allowRegistration)
|
||||
{
|
||||
throw new UnsupportedRepositoryOperationException();
|
||||
}
|
||||
namespaceService.registerNamespace(prefix, uri);
|
||||
}
|
||||
catch(org.alfresco.service.namespace.NamespaceException e)
|
||||
{
|
||||
throw new NamespaceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.NamespaceRegistry#unregisterNamespace(java.lang.String)
|
||||
*/
|
||||
public void unregisterNamespace(String prefix) throws NamespaceException, UnsupportedRepositoryOperationException, AccessDeniedException, RepositoryException
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!allowRegistration)
|
||||
{
|
||||
throw new UnsupportedRepositoryOperationException();
|
||||
}
|
||||
namespaceService.unregisterNamespace(prefix);
|
||||
}
|
||||
catch(org.alfresco.service.namespace.NamespaceException e)
|
||||
{
|
||||
throw new NamespaceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.NamespaceRegistry#getPrefixes()
|
||||
*/
|
||||
public String[] getPrefixes() throws RepositoryException
|
||||
{
|
||||
Collection<String> prefixes = namespaceService.getPrefixes();
|
||||
return prefixes.toArray(new String[prefixes.size()]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.NamespaceRegistry#getURIs()
|
||||
*/
|
||||
public String[] getURIs() throws RepositoryException
|
||||
{
|
||||
Collection<String> uris = namespaceService.getURIs();
|
||||
return uris.toArray(new String[uris.size()]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.NamespaceRegistry#getURI(java.lang.String)
|
||||
*/
|
||||
public String getURI(String prefix) throws NamespaceException, RepositoryException
|
||||
{
|
||||
String uri = namespaceService.getNamespaceURI(prefix);
|
||||
if (uri == null)
|
||||
{
|
||||
throw new NamespaceException("Prefix " + prefix + " is unknown.");
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.NamespaceRegistry#getPrefix(java.lang.String)
|
||||
*/
|
||||
public String getPrefix(String uri) throws NamespaceException, RepositoryException
|
||||
{
|
||||
Collection<String> prefixes = namespaceService.getPrefixes(uri);
|
||||
if (prefixes.size() == 0)
|
||||
{
|
||||
throw new NamespaceException("URI " + uri + " is unknown.");
|
||||
}
|
||||
// Return first prefix registered for uri
|
||||
return prefixes.iterator().next();
|
||||
}
|
||||
|
||||
}
|
126
source/java/org/alfresco/jcr/dictionary/NodeDefinitionImpl.java
Normal file
126
source/java/org/alfresco/jcr/dictionary/NodeDefinitionImpl.java
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.jcr.dictionary;
|
||||
|
||||
|
||||
import javax.jcr.nodetype.NodeDefinition;
|
||||
import javax.jcr.nodetype.NodeType;
|
||||
import javax.jcr.version.OnParentVersionAction;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
|
||||
|
||||
/**
|
||||
* Alfresco implementation of a JCR Node Definition
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public class NodeDefinitionImpl implements NodeDefinition
|
||||
{
|
||||
private NodeTypeManagerImpl typeManager;
|
||||
private ChildAssociationDefinition assocDef;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param typeManager
|
||||
* @param assocDef
|
||||
*/
|
||||
public NodeDefinitionImpl(NodeTypeManagerImpl typeManager, ChildAssociationDefinition assocDef)
|
||||
{
|
||||
this.typeManager = typeManager;
|
||||
this.assocDef = assocDef;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeDefinition#getRequiredPrimaryTypes()
|
||||
*/
|
||||
public NodeType[] getRequiredPrimaryTypes()
|
||||
{
|
||||
// Note: target class is mandatory in Alfresco
|
||||
ClassDefinition target = assocDef.getTargetClass();
|
||||
return new NodeType[] { typeManager.getNodeTypeImpl(target.getName()) };
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeDefinition#getDefaultPrimaryType()
|
||||
*/
|
||||
public NodeType getDefaultPrimaryType()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeDefinition#allowsSameNameSiblings()
|
||||
*/
|
||||
public boolean allowsSameNameSiblings()
|
||||
{
|
||||
return assocDef.getDuplicateChildNamesAllowed();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.ItemDefinition#getDeclaringNodeType()
|
||||
*/
|
||||
public NodeType getDeclaringNodeType()
|
||||
{
|
||||
return typeManager.getNodeTypeImpl(assocDef.getSourceClass().getName());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.ItemDefinition#getName()
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return assocDef.getName().toPrefixString(typeManager.getNamespaceService());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.ItemDefinition#isAutoCreated()
|
||||
*/
|
||||
public boolean isAutoCreated()
|
||||
{
|
||||
return isMandatory();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.ItemDefinition#isMandatory()
|
||||
*/
|
||||
public boolean isMandatory()
|
||||
{
|
||||
return assocDef.isTargetMandatory();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.ItemDefinition#getOnParentVersion()
|
||||
*/
|
||||
public int getOnParentVersion()
|
||||
{
|
||||
// TODO: Check this correct
|
||||
return OnParentVersionAction.INITIALIZE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.ItemDefinition#isProtected()
|
||||
*/
|
||||
public boolean isProtected()
|
||||
{
|
||||
return assocDef.isProtected();
|
||||
}
|
||||
|
||||
}
|
426
source/java/org/alfresco/jcr/dictionary/NodeTypeImpl.java
Normal file
426
source/java/org/alfresco/jcr/dictionary/NodeTypeImpl.java
Normal file
@@ -0,0 +1,426 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.jcr.dictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jcr.PropertyType;
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.Value;
|
||||
import javax.jcr.nodetype.NodeDefinition;
|
||||
import javax.jcr.nodetype.NodeType;
|
||||
import javax.jcr.nodetype.PropertyDefinition;
|
||||
|
||||
import org.alfresco.jcr.item.ValueImpl;
|
||||
import org.alfresco.jcr.item.property.JCRMixinTypesProperty;
|
||||
import org.alfresco.jcr.item.property.JCRPrimaryTypeProperty;
|
||||
import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Alfresco implementation of a Node Type Definition
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class NodeTypeImpl implements NodeType
|
||||
{
|
||||
// The required nt:base type specified by JCR
|
||||
public static QName NT_BASE = QName.createQName(JCRNamespace.NT_URI, "base");
|
||||
|
||||
// The optional mix:referenceable specified by JCR
|
||||
public static QName MIX_REFERENCEABLE = QName.createQName(JCRNamespace.MIX_URI, "referenceable");
|
||||
// The optional mix:lockable specified by JCR
|
||||
public static QName MIX_LOCKABLE = QName.createQName(JCRNamespace.MIX_URI, "lockable");
|
||||
// The optional mix:versionable specified by JCR
|
||||
public static QName MIX_VERSIONABLE = QName.createQName(JCRNamespace.MIX_URI, "versionable");
|
||||
|
||||
|
||||
private NodeTypeManagerImpl typeManager;
|
||||
private ClassDefinition classDefinition;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param classDefinition Alfresco class definition
|
||||
*/
|
||||
public NodeTypeImpl(NodeTypeManagerImpl typeManager, ClassDefinition classDefinition)
|
||||
{
|
||||
this.typeManager = typeManager;
|
||||
this.classDefinition = classDefinition;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#getName()
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return classDefinition.getName().toPrefixString(typeManager.getNamespaceService());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#isMixin()
|
||||
*/
|
||||
public boolean isMixin()
|
||||
{
|
||||
return classDefinition.isAspect();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#hasOrderableChildNodes()
|
||||
*/
|
||||
public boolean hasOrderableChildNodes()
|
||||
{
|
||||
// Note: For now, we don't expose this through JCR
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#getPrimaryItemName()
|
||||
*/
|
||||
public String getPrimaryItemName()
|
||||
{
|
||||
// NOTE: Alfresco does not support the notion of PrimaryItem (not yet anyway)
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#getSupertypes()
|
||||
*/
|
||||
public NodeType[] getSupertypes()
|
||||
{
|
||||
List<NodeType> nodeTypes = new ArrayList<NodeType>();
|
||||
NodeType[] declaredSupertypes = getDeclaredSupertypes();
|
||||
while (declaredSupertypes.length > 0)
|
||||
{
|
||||
// Alfresco supports single inheritence only
|
||||
NodeType supertype = declaredSupertypes[0];
|
||||
nodeTypes.add(supertype);
|
||||
declaredSupertypes = supertype.getDeclaredSupertypes();
|
||||
}
|
||||
return nodeTypes.toArray(new NodeType[nodeTypes.size()]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#getDeclaredSupertypes()
|
||||
*/
|
||||
public NodeType[] getDeclaredSupertypes()
|
||||
{
|
||||
// return no supertype when type is nt:base
|
||||
if (classDefinition.getName().equals(NT_BASE))
|
||||
{
|
||||
return new NodeType[] {};
|
||||
}
|
||||
|
||||
// return root type when no parent (nt:base if a type hierarchy)
|
||||
QName parent = classDefinition.getParentName();
|
||||
if (parent == null)
|
||||
{
|
||||
if (classDefinition.isAspect())
|
||||
{
|
||||
return new NodeType[] {};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new NodeType[] { typeManager.getNodeTypeImpl(NT_BASE) };
|
||||
}
|
||||
}
|
||||
|
||||
// return the supertype
|
||||
return new NodeType[] { typeManager.getNodeTypeImpl(parent) };
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#isNodeType(java.lang.String)
|
||||
*/
|
||||
public boolean isNodeType(String nodeTypeName)
|
||||
{
|
||||
QName name = QName.createQName(nodeTypeName, typeManager.getNamespaceService());
|
||||
|
||||
// is it one of standard types
|
||||
if (name.equals(NodeTypeImpl.NT_BASE))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// is it part of this class hierarchy
|
||||
return typeManager.getSession().getRepositoryImpl().getServiceRegistry().getDictionaryService().isSubClass(name, classDefinition.getName());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#getPropertyDefinitions()
|
||||
*/
|
||||
public PropertyDefinition[] getPropertyDefinitions()
|
||||
{
|
||||
Map<QName, org.alfresco.service.cmr.dictionary.PropertyDefinition> propDefs = classDefinition.getProperties();
|
||||
PropertyDefinition[] defs = new PropertyDefinition[propDefs.size() + (classDefinition.isAspect() ? 0 : 2)];
|
||||
int i = 0;
|
||||
for (org.alfresco.service.cmr.dictionary.PropertyDefinition propDef : propDefs.values())
|
||||
{
|
||||
defs[i++] = new PropertyDefinitionImpl(typeManager, propDef);
|
||||
}
|
||||
|
||||
if (!classDefinition.isAspect())
|
||||
{
|
||||
// add nt:base properties
|
||||
defs[i++] = typeManager.getPropertyDefinitionImpl(JCRPrimaryTypeProperty.PROPERTY_NAME);
|
||||
defs[i++] = typeManager.getPropertyDefinitionImpl(JCRMixinTypesProperty.PROPERTY_NAME);
|
||||
}
|
||||
|
||||
return defs;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#getDeclaredPropertyDefinitions()
|
||||
*/
|
||||
public PropertyDefinition[] getDeclaredPropertyDefinitions()
|
||||
{
|
||||
Map<QName, org.alfresco.service.cmr.dictionary.PropertyDefinition> propDefs = classDefinition.getProperties();
|
||||
List<PropertyDefinition> defs = new ArrayList<PropertyDefinition>();
|
||||
for (org.alfresco.service.cmr.dictionary.PropertyDefinition propDef : propDefs.values())
|
||||
{
|
||||
if (propDef.getContainerClass().equals(classDefinition))
|
||||
{
|
||||
defs.add(new PropertyDefinitionImpl(typeManager, propDef));
|
||||
}
|
||||
}
|
||||
|
||||
if (classDefinition.equals(NT_BASE))
|
||||
{
|
||||
// add nt:base properties
|
||||
defs.add(typeManager.getPropertyDefinitionImpl(JCRPrimaryTypeProperty.PROPERTY_NAME));
|
||||
defs.add(typeManager.getPropertyDefinitionImpl(JCRMixinTypesProperty.PROPERTY_NAME));
|
||||
}
|
||||
|
||||
return defs.toArray(new PropertyDefinition[defs.size()]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#getChildNodeDefinitions()
|
||||
*/
|
||||
public NodeDefinition[] getChildNodeDefinitions()
|
||||
{
|
||||
Map<QName, ChildAssociationDefinition> assocDefs = classDefinition.getChildAssociations();
|
||||
NodeDefinition[] defs = new NodeDefinition[assocDefs.size()];
|
||||
int i = 0;
|
||||
for (ChildAssociationDefinition assocDef : assocDefs.values())
|
||||
{
|
||||
defs[i++] = new NodeDefinitionImpl(typeManager, assocDef);
|
||||
}
|
||||
return defs;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#getDeclaredChildNodeDefinitions()
|
||||
*/
|
||||
public NodeDefinition[] getDeclaredChildNodeDefinitions()
|
||||
{
|
||||
Map<QName, ChildAssociationDefinition> assocDefs = classDefinition.getChildAssociations();
|
||||
List<NodeDefinition> defs = new ArrayList<NodeDefinition>();
|
||||
for (ChildAssociationDefinition assocDef : assocDefs.values())
|
||||
{
|
||||
if (assocDef.getSourceClass().equals(classDefinition))
|
||||
{
|
||||
defs.add(new NodeDefinitionImpl(typeManager, assocDef));
|
||||
}
|
||||
}
|
||||
return defs.toArray(new NodeDefinition[defs.size()]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#canSetProperty(java.lang.String, javax.jcr.Value)
|
||||
*/
|
||||
public boolean canSetProperty(String propertyName, Value value)
|
||||
{
|
||||
try
|
||||
{
|
||||
// is an attempt to remove property being made
|
||||
if (value == null)
|
||||
{
|
||||
return canRemoveItem(propertyName);
|
||||
}
|
||||
|
||||
// retrieve property definition
|
||||
QName propertyQName = QName.createQName(propertyName, typeManager.getNamespaceService());
|
||||
Map<QName, org.alfresco.service.cmr.dictionary.PropertyDefinition> propDefs = classDefinition.getProperties();
|
||||
org.alfresco.service.cmr.dictionary.PropertyDefinition propDef = propDefs.get(propertyQName);
|
||||
if (propDef == null)
|
||||
{
|
||||
// Alfresco doesn't have residual properties yet
|
||||
return false;
|
||||
}
|
||||
|
||||
// is property read-write
|
||||
if (propDef.isProtected() || propDef.isMultiValued())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// get required type to convert to
|
||||
int requiredType = DataTypeMap.convertDataTypeToPropertyType(propDef.getDataType().getName());
|
||||
if (requiredType == PropertyType.UNDEFINED)
|
||||
{
|
||||
requiredType = value.getType();
|
||||
}
|
||||
|
||||
// convert value to required type
|
||||
// Note: Invalid conversion will throw exception
|
||||
ValueImpl.getValue(typeManager.getSession().getTypeConverter(), requiredType, value);
|
||||
|
||||
// Note: conversion succeeded
|
||||
return true;
|
||||
}
|
||||
catch(RepositoryException e)
|
||||
{
|
||||
// Note: Not much can be done really
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#canSetProperty(java.lang.String, javax.jcr.Value[])
|
||||
*/
|
||||
public boolean canSetProperty(String propertyName, Value[] values)
|
||||
{
|
||||
try
|
||||
{
|
||||
// is an attempt to remove property being made
|
||||
if (values == null)
|
||||
{
|
||||
return canRemoveItem(propertyName);
|
||||
}
|
||||
|
||||
// retrieve property definition
|
||||
QName propertyQName = QName.createQName(propertyName, typeManager.getNamespaceService());
|
||||
Map<QName, org.alfresco.service.cmr.dictionary.PropertyDefinition> propDefs = classDefinition.getProperties();
|
||||
org.alfresco.service.cmr.dictionary.PropertyDefinition propDef = propDefs.get(propertyQName);
|
||||
if (propDef == null)
|
||||
{
|
||||
// Alfresco doesn't have residual properties yet
|
||||
return false;
|
||||
}
|
||||
|
||||
// is property read write
|
||||
if (propDef.isProtected() || !propDef.isMultiValued())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// determine type of values to check
|
||||
int valueType = PropertyType.UNDEFINED;
|
||||
for (Value value : values)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
if (valueType != PropertyType.UNDEFINED && value.getType() != valueType)
|
||||
{
|
||||
// do not allow collection mixed type values
|
||||
return false;
|
||||
}
|
||||
valueType = value.getType();
|
||||
}
|
||||
}
|
||||
|
||||
// get required type to convert to
|
||||
int requiredType = DataTypeMap.convertDataTypeToPropertyType(propDef.getDataType().getName());
|
||||
if (requiredType == PropertyType.UNDEFINED)
|
||||
{
|
||||
requiredType = valueType;
|
||||
}
|
||||
|
||||
// convert values to required format
|
||||
// Note: Invalid conversion will throw exception
|
||||
for (Value value : values)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
ValueImpl.getValue(typeManager.getSession().getTypeConverter(), requiredType, value);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: conversion succeeded
|
||||
return true;
|
||||
}
|
||||
catch(RepositoryException e)
|
||||
{
|
||||
// Note: Not much can be done really
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#canAddChildNode(java.lang.String)
|
||||
*/
|
||||
public boolean canAddChildNode(String childNodeName)
|
||||
{
|
||||
// NOTE: Alfresco does not have default primary type notion
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#canAddChildNode(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public boolean canAddChildNode(String childNodeName, String nodeTypeName)
|
||||
{
|
||||
boolean canAdd = false;
|
||||
Map<QName, ChildAssociationDefinition> assocDefs = classDefinition.getChildAssociations();
|
||||
QName childNodeQName = QName.createQName(childNodeName, typeManager.getNamespaceService());
|
||||
ChildAssociationDefinition assocDef = assocDefs.get(childNodeQName);
|
||||
if (assocDef != null)
|
||||
{
|
||||
QName nodeTypeQName = QName.createQName(nodeTypeName, typeManager.getNamespaceService());
|
||||
DictionaryService dictionaryService = typeManager.getSession().getRepositoryImpl().getServiceRegistry().getDictionaryService();
|
||||
canAdd = dictionaryService.isSubClass(nodeTypeQName, assocDef.getTargetClass().getName());
|
||||
}
|
||||
return canAdd;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeType#canRemoveItem(java.lang.String)
|
||||
*/
|
||||
public boolean canRemoveItem(String itemName)
|
||||
{
|
||||
boolean isProtected = false;
|
||||
boolean isMandatory = false;
|
||||
|
||||
// TODO: Property and Association names can clash? What to do?
|
||||
QName itemQName = QName.createQName(itemName, typeManager.getNamespaceService());
|
||||
Map<QName, org.alfresco.service.cmr.dictionary.PropertyDefinition> propDefs = classDefinition.getProperties();
|
||||
org.alfresco.service.cmr.dictionary.PropertyDefinition propDef = propDefs.get(itemQName);
|
||||
if (propDef != null)
|
||||
{
|
||||
isProtected = propDef.isProtected();
|
||||
isMandatory = propDef.isMandatory();
|
||||
}
|
||||
Map<QName, ChildAssociationDefinition> assocDefs = classDefinition.getChildAssociations();
|
||||
ChildAssociationDefinition assocDef = assocDefs.get(itemQName);
|
||||
if (assocDef != null)
|
||||
{
|
||||
isProtected |= assocDef.isProtected();
|
||||
isMandatory |= assocDef.isTargetMandatory();
|
||||
}
|
||||
|
||||
return !isProtected && !isMandatory;
|
||||
}
|
||||
|
||||
}
|
163
source/java/org/alfresco/jcr/dictionary/NodeTypeManagerImpl.java
Normal file
163
source/java/org/alfresco/jcr/dictionary/NodeTypeManagerImpl.java
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.jcr.dictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.nodetype.NoSuchNodeTypeException;
|
||||
import javax.jcr.nodetype.NodeType;
|
||||
import javax.jcr.nodetype.NodeTypeIterator;
|
||||
import javax.jcr.nodetype.NodeTypeManager;
|
||||
|
||||
import org.alfresco.jcr.session.SessionImpl;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Alfresco implementation of JCR Node Type Manager
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class NodeTypeManagerImpl implements NodeTypeManager
|
||||
{
|
||||
private SessionImpl session;
|
||||
private NamespaceService namespaceService;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param dictionaryService dictionary service
|
||||
* @param namespaceService namespace service (global repository registry)
|
||||
*/
|
||||
public NodeTypeManagerImpl(SessionImpl session, NamespaceService namespaceService)
|
||||
{
|
||||
this.session = session;
|
||||
this.namespaceService = namespaceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Dictionary Service
|
||||
*
|
||||
* @return the dictionary service
|
||||
*/
|
||||
public SessionImpl getSession()
|
||||
{
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Namespace Service
|
||||
*
|
||||
* @return the namespace service
|
||||
*/
|
||||
public NamespaceService getNamespaceService()
|
||||
{
|
||||
return namespaceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Node Type Implementation for given Class Name
|
||||
*
|
||||
* @param nodeTypeName alfresco class name
|
||||
* @return the node type
|
||||
*/
|
||||
public NodeTypeImpl getNodeTypeImpl(QName nodeTypeName)
|
||||
{
|
||||
// TODO: Might be worth caching here... wait and see
|
||||
NodeTypeImpl nodeType = null;
|
||||
ClassDefinition definition = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getClass(nodeTypeName);
|
||||
if (definition != null)
|
||||
{
|
||||
nodeType = new NodeTypeImpl(this, definition);
|
||||
}
|
||||
return nodeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Property Definition Implementation for given Property Name
|
||||
*
|
||||
* @param propertyName alfresco property name
|
||||
* @return the property
|
||||
*/
|
||||
public PropertyDefinitionImpl getPropertyDefinitionImpl(QName propertyName)
|
||||
{
|
||||
// TODO: Might be worth caching here... wait and see
|
||||
PropertyDefinitionImpl propDef = null;
|
||||
PropertyDefinition definition = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getProperty(propertyName);
|
||||
if (definition != null)
|
||||
{
|
||||
propDef = new PropertyDefinitionImpl(this, definition);
|
||||
}
|
||||
return propDef;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeTypeManager#getNodeType(java.lang.String)
|
||||
*/
|
||||
public NodeType getNodeType(String nodeTypeName) throws NoSuchNodeTypeException, RepositoryException
|
||||
{
|
||||
QName name = QName.createQName(nodeTypeName, namespaceService);
|
||||
NodeTypeImpl nodeTypeImpl = getNodeTypeImpl(name);
|
||||
if (nodeTypeImpl == null)
|
||||
{
|
||||
throw new NoSuchNodeTypeException("Node type " + nodeTypeName + " does not exist");
|
||||
}
|
||||
return nodeTypeImpl;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeTypeManager#getAllNodeTypes()
|
||||
*/
|
||||
public NodeTypeIterator getAllNodeTypes() throws RepositoryException
|
||||
{
|
||||
Collection<QName> typeNames = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getAllTypes();
|
||||
Collection<QName> aspectNames = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getAllAspects();
|
||||
List<QName> typesList = new ArrayList<QName>(typeNames.size() + aspectNames.size());
|
||||
typesList.addAll(typeNames);
|
||||
typesList.addAll(aspectNames);
|
||||
return new NodeTypeNameIterator(this, typesList);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeTypeManager#getPrimaryNodeTypes()
|
||||
*/
|
||||
public NodeTypeIterator getPrimaryNodeTypes() throws RepositoryException
|
||||
{
|
||||
Collection<QName> typeNames = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getAllTypes();
|
||||
List<QName> typesList = new ArrayList<QName>(typeNames.size());
|
||||
typesList.addAll(typeNames);
|
||||
return new NodeTypeNameIterator(this, typesList);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeTypeManager#getMixinNodeTypes()
|
||||
*/
|
||||
public NodeTypeIterator getMixinNodeTypes() throws RepositoryException
|
||||
{
|
||||
Collection<QName> typeNames = session.getRepositoryImpl().getServiceRegistry().getDictionaryService().getAllAspects();
|
||||
List<QName> typesList = new ArrayList<QName>(typeNames.size());
|
||||
typesList.addAll(typeNames);
|
||||
return new NodeTypeNameIterator(this, typesList);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.jcr.dictionary;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.jcr.nodetype.NodeType;
|
||||
import javax.jcr.nodetype.NodeTypeIterator;
|
||||
|
||||
import org.alfresco.jcr.util.AbstractRangeIterator;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Alfresco implementation of a Node Type Iterator
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class NodeTypeNameIterator extends AbstractRangeIterator
|
||||
implements NodeTypeIterator
|
||||
{
|
||||
private NodeTypeManagerImpl typeManager;
|
||||
private List<QName> nodeTypeNames;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param context session context
|
||||
* @param nodeTypes node type list
|
||||
*/
|
||||
public NodeTypeNameIterator(NodeTypeManagerImpl typeManager, List<QName> nodeTypeNames)
|
||||
{
|
||||
this.typeManager = typeManager;
|
||||
this.nodeTypeNames = nodeTypeNames;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.NodeTypeIterator#nextNodeType()
|
||||
*/
|
||||
public NodeType nextNodeType()
|
||||
{
|
||||
long position = skip();
|
||||
QName name = nodeTypeNames.get((int)position);
|
||||
return typeManager.getNodeTypeImpl(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.RangeIterator#getSize()
|
||||
*/
|
||||
public long getSize()
|
||||
{
|
||||
return nodeTypeNames.size();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#next()
|
||||
*/
|
||||
public Object next()
|
||||
{
|
||||
return nextNodeType();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.jcr.dictionary;
|
||||
|
||||
import javax.jcr.Value;
|
||||
import javax.jcr.nodetype.NodeType;
|
||||
import javax.jcr.nodetype.PropertyDefinition;
|
||||
import javax.jcr.version.OnParentVersionAction;
|
||||
|
||||
import org.alfresco.jcr.item.ValueImpl;
|
||||
import org.alfresco.jcr.item.property.JCRMixinTypesProperty;
|
||||
import org.alfresco.jcr.item.property.JCRPrimaryTypeProperty;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
|
||||
/**
|
||||
* Alfresco implementation of a JCR Property Definition
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class PropertyDefinitionImpl implements PropertyDefinition
|
||||
{
|
||||
/** Session */
|
||||
private NodeTypeManagerImpl typeManager;
|
||||
|
||||
/** Alfresco Property Definition */
|
||||
private org.alfresco.service.cmr.dictionary.PropertyDefinition propDef;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param propDef Alfresco Property Definition
|
||||
*/
|
||||
public PropertyDefinitionImpl(NodeTypeManagerImpl typeManager, org.alfresco.service.cmr.dictionary.PropertyDefinition propDef)
|
||||
{
|
||||
this.typeManager = typeManager;
|
||||
this.propDef = propDef;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.PropertyDefinition#getRequiredType()
|
||||
*/
|
||||
public int getRequiredType()
|
||||
{
|
||||
// TODO: Switch on data type
|
||||
if (propDef.getName().equals(ContentModel.PROP_CONTENT))
|
||||
{
|
||||
return DataTypeMap.convertDataTypeToPropertyType(DataTypeDefinition.CONTENT);
|
||||
}
|
||||
return DataTypeMap.convertDataTypeToPropertyType(propDef.getDataType().getName());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.PropertyDefinition#getValueConstraints()
|
||||
*/
|
||||
public String[] getValueConstraints()
|
||||
{
|
||||
return new String[] {};
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.PropertyDefinition#getDefaultValues()
|
||||
*/
|
||||
public Value[] getDefaultValues()
|
||||
{
|
||||
String defaultValue = propDef.getDefaultValue();
|
||||
if (defaultValue == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Value[] { new ValueImpl(typeManager.getSession(), getRequiredType(), defaultValue) };
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.PropertyDefinition#isMultiple()
|
||||
*/
|
||||
public boolean isMultiple()
|
||||
{
|
||||
return propDef.isMultiValued();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.ItemDefinition#getDeclaringNodeType()
|
||||
*/
|
||||
public NodeType getDeclaringNodeType()
|
||||
{
|
||||
ClassDefinition declaringClass = propDef.getContainerClass();
|
||||
return typeManager.getNodeTypeImpl(declaringClass.getName());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.ItemDefinition#getName()
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return propDef.getName().toPrefixString(typeManager.getNamespaceService());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.ItemDefinition#isAutoCreated()
|
||||
*/
|
||||
public boolean isAutoCreated()
|
||||
{
|
||||
return isMandatory();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.ItemDefinition#isMandatory()
|
||||
*/
|
||||
public boolean isMandatory()
|
||||
{
|
||||
return propDef.isMandatory();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.ItemDefinition#getOnParentVersion()
|
||||
*/
|
||||
public int getOnParentVersion()
|
||||
{
|
||||
// TODO: There's no equivalent in Alfresco, so hard code for now
|
||||
if (propDef.getName().equals(JCRPrimaryTypeProperty.PROPERTY_NAME) ||
|
||||
propDef.getName().equals(JCRMixinTypesProperty.PROPERTY_NAME))
|
||||
{
|
||||
return OnParentVersionAction.COMPUTE;
|
||||
}
|
||||
|
||||
// TODO: Check this
|
||||
return OnParentVersionAction.INITIALIZE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.nodetype.ItemDefinition#isProtected()
|
||||
*/
|
||||
public boolean isProtected()
|
||||
{
|
||||
return propDef.isProtected();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.jcr.dictionary;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import org.alfresco.jcr.session.SessionImpl;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Encapsulate Versionable Mixin behaviour mapping to Alfresco
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class VersionableMixin implements ClassMap.AddMixin, ClassMap.RemoveMixin
|
||||
{
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.jcr.dictionary.ClassMap.AddMixin#preAddMixin(org.alfresco.jcr.session.SessionImpl, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public Map<QName, Serializable> preAddMixin(SessionImpl session, NodeRef nodeRef)
|
||||
{
|
||||
// switch off auto-versioning
|
||||
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
|
||||
properties.put(ContentModel.PROP_INITIAL_VERSION, false);
|
||||
properties.put(ContentModel.PROP_AUTO_VERSION, false);
|
||||
return properties;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.jcr.dictionary.ClassMap.AddMixin#postAddMixin(org.alfresco.jcr.session.SessionImpl, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void postAddMixin(SessionImpl session, NodeRef nodeRef)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.jcr.dictionary.ClassMap.RemoveMixin#preRemoveMixin(org.alfresco.jcr.session.SessionImpl, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void preRemoveMixin(SessionImpl session, NodeRef nodeRef)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.jcr.dictionary.ClassMap.RemoveMixin#postRemoveMixin(org.alfresco.jcr.session.SessionImpl, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void postRemoveMixin(SessionImpl session, NodeRef nodeRef)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user