mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Moving to root below branch label
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
366
source/java/org/alfresco/repo/dictionary/CompiledModel.java
Normal file
366
source/java/org/alfresco/repo/dictionary/CompiledModel.java
Normal file
@@ -0,0 +1,366 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.namespace.DynamicNamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.NamespaceException;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Compiled representation of a model definition.
|
||||
*
|
||||
* In this case, compiled means that
|
||||
* a) all references between model items have been resolved
|
||||
* b) inheritence of class features have been flattened
|
||||
* c) overridden class features have been resolved
|
||||
*
|
||||
* A compiled model also represents a valid model.
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
/*package*/ class CompiledModel implements ModelQuery
|
||||
{
|
||||
|
||||
// Logger
|
||||
private static final Log logger = LogFactory.getLog(DictionaryDAOImpl.class);
|
||||
|
||||
private M2Model model;
|
||||
private ModelDefinition modelDefinition;
|
||||
private Map<QName, DataTypeDefinition> dataTypes = new HashMap<QName, DataTypeDefinition>();
|
||||
private Map<QName, ClassDefinition> classes = new HashMap<QName, ClassDefinition>();
|
||||
private Map<QName, TypeDefinition> types = new HashMap<QName, TypeDefinition>();
|
||||
private Map<QName, AspectDefinition> aspects = new HashMap<QName, AspectDefinition>();
|
||||
private Map<QName, PropertyDefinition> properties = new HashMap<QName, PropertyDefinition>();
|
||||
private Map<QName, AssociationDefinition> associations = new HashMap<QName, AssociationDefinition>();
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param model model definition
|
||||
* @param dictionaryDAO dictionary DAO
|
||||
* @param namespaceDAO namespace DAO
|
||||
*/
|
||||
/*package*/ CompiledModel(M2Model model, DictionaryDAO dictionaryDAO, NamespaceDAO namespaceDAO)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Phase 1: Construct model definitions from model entries
|
||||
// resolving qualified names
|
||||
this.model = model;
|
||||
constructDefinitions(model, dictionaryDAO, namespaceDAO);
|
||||
|
||||
// Phase 2: Resolve dependencies between model definitions
|
||||
ModelQuery query = new DelegateModelQuery(this, dictionaryDAO);
|
||||
resolveDependencies(query);
|
||||
|
||||
// Phase 3: Resolve inheritance of values within class hierachy
|
||||
resolveInheritance(query);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new DictionaryException("Failed to compile model " + model.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the model definition
|
||||
*/
|
||||
/*package*/ M2Model getM2Model()
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct compiled definitions
|
||||
*
|
||||
* @param model model definition
|
||||
* @param dictionaryDAO dictionary DAO
|
||||
* @param namespaceDAO namespace DAO
|
||||
*/
|
||||
private void constructDefinitions(M2Model model, DictionaryDAO dictionaryDAO, NamespaceDAO namespaceDAO)
|
||||
{
|
||||
NamespacePrefixResolver localPrefixes = createLocalPrefixResolver(model, namespaceDAO);
|
||||
|
||||
// Construct Model Definition
|
||||
modelDefinition = new M2ModelDefinition(model, localPrefixes);
|
||||
|
||||
// Construct Property Types
|
||||
for (M2DataType propType : model.getPropertyTypes())
|
||||
{
|
||||
M2DataTypeDefinition def = new M2DataTypeDefinition(modelDefinition, propType, localPrefixes);
|
||||
if (dataTypes.containsKey(def.getName()))
|
||||
{
|
||||
throw new DictionaryException("Found duplicate property type definition " + propType.getName());
|
||||
}
|
||||
dataTypes.put(def.getName(), def);
|
||||
}
|
||||
|
||||
// Construct Type Definitions
|
||||
for (M2Type type : model.getTypes())
|
||||
{
|
||||
M2TypeDefinition def = new M2TypeDefinition(modelDefinition, type, localPrefixes, properties, associations);
|
||||
if (classes.containsKey(def.getName()))
|
||||
{
|
||||
throw new DictionaryException("Found duplicate class definition " + type.getName() + " (a type)");
|
||||
}
|
||||
classes.put(def.getName(), def);
|
||||
types.put(def.getName(), def);
|
||||
}
|
||||
|
||||
// Construct Aspect Definitions
|
||||
for (M2Aspect aspect : model.getAspects())
|
||||
{
|
||||
M2AspectDefinition def = new M2AspectDefinition(modelDefinition, aspect, localPrefixes, properties, associations);
|
||||
if (classes.containsKey(def.getName()))
|
||||
{
|
||||
throw new DictionaryException("Found duplicate class definition " + aspect.getName() + " (an aspect)");
|
||||
}
|
||||
classes.put(def.getName(), def);
|
||||
aspects.put(def.getName(), def);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a local namespace prefix resolver containing the namespaces defined and imported
|
||||
* in the model
|
||||
*
|
||||
* @param model model definition
|
||||
* @param namespaceDAO namespace DAO
|
||||
* @return the local namespace prefix resolver
|
||||
*/
|
||||
private NamespacePrefixResolver createLocalPrefixResolver(M2Model model, NamespaceDAO namespaceDAO)
|
||||
{
|
||||
// Retrieve set of existing URIs for validation purposes
|
||||
Collection<String> uris = namespaceDAO.getURIs();
|
||||
|
||||
// Create a namespace prefix resolver based on imported and defined
|
||||
// namespaces within the model
|
||||
DynamicNamespacePrefixResolver prefixResolver = new DynamicNamespacePrefixResolver(null);
|
||||
for (M2Namespace imported : model.getImports())
|
||||
{
|
||||
String uri = imported.getUri();
|
||||
if (!uris.contains(uri))
|
||||
{
|
||||
throw new NamespaceException("URI " + uri + " cannot be imported as it is not defined (with prefix " + imported.getPrefix());
|
||||
}
|
||||
prefixResolver.registerNamespace(imported.getPrefix(), uri);
|
||||
}
|
||||
for (M2Namespace defined : model.getNamespaces())
|
||||
{
|
||||
prefixResolver.registerNamespace(defined.getPrefix(), defined.getUri());
|
||||
}
|
||||
return prefixResolver;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resolve dependencies between model items
|
||||
*
|
||||
* @param query support for querying other items in model
|
||||
*/
|
||||
private void resolveDependencies(ModelQuery query)
|
||||
{
|
||||
for (DataTypeDefinition def : dataTypes.values())
|
||||
{
|
||||
((M2DataTypeDefinition)def).resolveDependencies(query);
|
||||
}
|
||||
for (ClassDefinition def : classes.values())
|
||||
{
|
||||
((M2ClassDefinition)def).resolveDependencies(query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resolve class feature inheritence
|
||||
*
|
||||
* @param query support for querying other items in model
|
||||
*/
|
||||
private void resolveInheritance(ModelQuery query)
|
||||
{
|
||||
// Calculate order of class processing (root to leaf)
|
||||
Map<Integer,List<ClassDefinition>> order = new TreeMap<Integer,List<ClassDefinition>>();
|
||||
for (ClassDefinition def : classes.values())
|
||||
{
|
||||
// Calculate class depth in hierarchy
|
||||
int depth = 0;
|
||||
QName parentName = def.getParentName();
|
||||
while (parentName != null)
|
||||
{
|
||||
ClassDefinition parentClass = getClass(parentName);
|
||||
if (parentClass == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
depth = depth +1;
|
||||
parentName = parentClass.getParentName();
|
||||
}
|
||||
|
||||
// Map class to depth
|
||||
List<ClassDefinition> classes = order.get(depth);
|
||||
if (classes == null)
|
||||
{
|
||||
classes = new ArrayList<ClassDefinition>();
|
||||
order.put(depth, classes);
|
||||
}
|
||||
classes.add(def);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Resolving inheritance: class " + def.getName() + " found at depth " + depth);
|
||||
}
|
||||
|
||||
// Resolve inheritance of each class
|
||||
for (int depth = 0; depth < order.size(); depth++)
|
||||
{
|
||||
for (ClassDefinition def : order.get(depth))
|
||||
{
|
||||
((M2ClassDefinition)def).resolveInheritance(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the compiled model definition
|
||||
*/
|
||||
public ModelDefinition getModelDefinition()
|
||||
{
|
||||
return modelDefinition;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the compiled property types
|
||||
*/
|
||||
public Collection<DataTypeDefinition> getDataTypes()
|
||||
{
|
||||
return dataTypes.values();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the compiled types
|
||||
*/
|
||||
public Collection<TypeDefinition> getTypes()
|
||||
{
|
||||
return types.values();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the compiled aspects
|
||||
*/
|
||||
public Collection<AspectDefinition> getAspects()
|
||||
{
|
||||
return aspects.values();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getPropertyType(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public DataTypeDefinition getDataType(QName name)
|
||||
{
|
||||
return dataTypes.get(name);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ModelQuery#getDataType(java.lang.Class)
|
||||
*/
|
||||
public DataTypeDefinition getDataType(Class javaClass)
|
||||
{
|
||||
for (DataTypeDefinition dataTypeDef : dataTypes.values())
|
||||
{
|
||||
if (dataTypeDef.getJavaClassName().equals(javaClass.getName()))
|
||||
{
|
||||
return dataTypeDef;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getType(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public TypeDefinition getType(QName name)
|
||||
{
|
||||
return types.get(name);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getAspect(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public AspectDefinition getAspect(QName name)
|
||||
{
|
||||
return aspects.get(name);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getClass(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public ClassDefinition getClass(QName name)
|
||||
{
|
||||
return classes.get(name);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getProperty(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public PropertyDefinition getProperty(QName name)
|
||||
{
|
||||
return properties.get(name);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getAssociation(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public AssociationDefinition getAssociation(QName name)
|
||||
{
|
||||
return associations.get(name);
|
||||
}
|
||||
|
||||
}
|
151
source/java/org/alfresco/repo/dictionary/DelegateModelQuery.java
Normal file
151
source/java/org/alfresco/repo/dictionary/DelegateModelQuery.java
Normal file
@@ -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.repo.dictionary;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Model query that delegates its search if itself cannot find the model
|
||||
* item required.
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
/*package*/ class DelegateModelQuery implements ModelQuery
|
||||
{
|
||||
|
||||
private ModelQuery query;
|
||||
private ModelQuery delegate;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param query
|
||||
* @param delegate
|
||||
*/
|
||||
/*package*/ DelegateModelQuery(ModelQuery query, ModelQuery delegate)
|
||||
{
|
||||
this.query = query;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getPropertyType(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public DataTypeDefinition getDataType(QName name)
|
||||
{
|
||||
DataTypeDefinition def = query.getDataType(name);
|
||||
if (def == null)
|
||||
{
|
||||
def = delegate.getDataType(name);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ModelQuery#getDataType(java.lang.Class)
|
||||
*/
|
||||
public DataTypeDefinition getDataType(Class javaClass)
|
||||
{
|
||||
DataTypeDefinition def = query.getDataType(javaClass);
|
||||
if (def == null)
|
||||
{
|
||||
def = delegate.getDataType(javaClass);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getType(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public TypeDefinition getType(QName name)
|
||||
{
|
||||
TypeDefinition def = query.getType(name);
|
||||
if (def == null)
|
||||
{
|
||||
def = delegate.getType(name);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getAspect(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public AspectDefinition getAspect(QName name)
|
||||
{
|
||||
AspectDefinition def = query.getAspect(name);
|
||||
if (def == null)
|
||||
{
|
||||
def = delegate.getAspect(name);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getClass(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public ClassDefinition getClass(QName name)
|
||||
{
|
||||
ClassDefinition def = query.getClass(name);
|
||||
if (def == null)
|
||||
{
|
||||
def = delegate.getClass(name);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getProperty(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public PropertyDefinition getProperty(QName name)
|
||||
{
|
||||
PropertyDefinition def = query.getProperty(name);
|
||||
if (def == null)
|
||||
{
|
||||
def = delegate.getProperty(name);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getAssociation(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public AssociationDefinition getAssociation(QName name)
|
||||
{
|
||||
AssociationDefinition def = query.getAssociation(name);
|
||||
if (def == null)
|
||||
{
|
||||
def = delegate.getAssociation(name);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||
|
||||
|
||||
/**
|
||||
* Bootstrap Dictionary DAO with pre-defined models
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public class DictionaryBootstrap
|
||||
{
|
||||
// The list of models to bootstrap with
|
||||
private List<String> models = new ArrayList<String>();
|
||||
|
||||
// The list of model resource bundles to bootstrap with
|
||||
private List<String> resourceBundles = new ArrayList<String>();
|
||||
|
||||
// Dictionary DAO
|
||||
private DictionaryDAO dictionaryDAO = null;
|
||||
|
||||
/**
|
||||
* Sets the Dictionary DAO
|
||||
*
|
||||
* @param dictionaryDAO
|
||||
*/
|
||||
public void setDictionaryDAO(DictionaryDAO dictionaryDAO)
|
||||
{
|
||||
this.dictionaryDAO = dictionaryDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the initial list of models to bootstrap with
|
||||
*
|
||||
* @param modelResources the model names
|
||||
*/
|
||||
public void setModels(List<String> modelResources)
|
||||
{
|
||||
this.models = modelResources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the initial list of models to bootstrap with
|
||||
*
|
||||
* @param modelResources the model names
|
||||
*/
|
||||
public void setLabels(List<String> labels)
|
||||
{
|
||||
this.resourceBundles = labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap the Dictionary
|
||||
*/
|
||||
public void bootstrap()
|
||||
{
|
||||
// register models
|
||||
for (String bootstrapModel : models)
|
||||
{
|
||||
InputStream modelStream = getClass().getClassLoader().getResourceAsStream(bootstrapModel);
|
||||
if (modelStream == null)
|
||||
{
|
||||
throw new DictionaryException("Could not find bootstrap model " + bootstrapModel);
|
||||
}
|
||||
try
|
||||
{
|
||||
M2Model model = M2Model.createModel(modelStream);
|
||||
dictionaryDAO.putModel(model);
|
||||
}
|
||||
catch(DictionaryException e)
|
||||
{
|
||||
throw new DictionaryException("Could not import bootstrap model " + bootstrapModel, e);
|
||||
}
|
||||
}
|
||||
|
||||
// register models
|
||||
for (String resourceBundle : resourceBundles)
|
||||
{
|
||||
I18NUtil.registerResourceBundle(resourceBundle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.InvalidTypeException;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
|
||||
|
||||
/**
|
||||
* Data Dictionary Service Implementation
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class DictionaryComponent implements DictionaryService
|
||||
{
|
||||
private DictionaryDAO dictionaryDAO;
|
||||
|
||||
|
||||
// TODO: Check passed arguments are valid
|
||||
|
||||
/**
|
||||
* Sets the Meta Model DAO
|
||||
*
|
||||
* @param metaModelDAO meta model DAO
|
||||
*/
|
||||
public void setDictionaryDAO(DictionaryDAO dictionaryDAO)
|
||||
{
|
||||
this.dictionaryDAO = dictionaryDAO;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getAllModels()
|
||||
*/
|
||||
public Collection<QName> getAllModels()
|
||||
{
|
||||
return dictionaryDAO.getModels();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getModel(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public ModelDefinition getModel(QName model)
|
||||
{
|
||||
return dictionaryDAO.getModel(model);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getAllPropertyTypes()
|
||||
*/
|
||||
public Collection<QName> getAllDataTypes()
|
||||
{
|
||||
Collection<QName> propertyTypes = new ArrayList<QName>();
|
||||
for (QName model : getAllModels())
|
||||
{
|
||||
propertyTypes.addAll(getAspects(model));
|
||||
}
|
||||
return propertyTypes;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getPropertyTypes(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public Collection<QName> getDataTypes(QName model)
|
||||
{
|
||||
Collection<DataTypeDefinition> propertyTypes = dictionaryDAO.getDataTypes(model);
|
||||
Collection<QName> qnames = new ArrayList<QName>(propertyTypes.size());
|
||||
for (DataTypeDefinition def : propertyTypes)
|
||||
{
|
||||
qnames.add(def.getName());
|
||||
}
|
||||
return qnames;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getAllTypes()
|
||||
*/
|
||||
public Collection<QName> getAllTypes()
|
||||
{
|
||||
Collection<QName> types = new ArrayList<QName>();
|
||||
for (QName model : getAllModels())
|
||||
{
|
||||
types.addAll(getTypes(model));
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getTypes(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public Collection<QName> getTypes(QName model)
|
||||
{
|
||||
Collection<TypeDefinition> types = dictionaryDAO.getTypes(model);
|
||||
Collection<QName> qnames = new ArrayList<QName>(types.size());
|
||||
for (TypeDefinition def : types)
|
||||
{
|
||||
qnames.add(def.getName());
|
||||
}
|
||||
return qnames;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getAllAspects()
|
||||
*/
|
||||
public Collection<QName> getAllAspects()
|
||||
{
|
||||
Collection<QName> aspects = new ArrayList<QName>();
|
||||
for (QName model : getAllModels())
|
||||
{
|
||||
aspects.addAll(getAspects(model));
|
||||
}
|
||||
return aspects;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getAspects(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public Collection<QName> getAspects(QName model)
|
||||
{
|
||||
Collection<AspectDefinition> aspects = dictionaryDAO.getAspects(model);
|
||||
Collection<QName> qnames = new ArrayList<QName>(aspects.size());
|
||||
for (AspectDefinition def : aspects)
|
||||
{
|
||||
qnames.add(def.getName());
|
||||
}
|
||||
return qnames;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#isSubClass(org.alfresco.repo.ref.QName, org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public boolean isSubClass(QName className, QName ofClassName)
|
||||
{
|
||||
// Validate arguments
|
||||
ParameterCheck.mandatory("className", className);
|
||||
ParameterCheck.mandatory("ofClassName", ofClassName);
|
||||
ClassDefinition classDef = getClass(className);
|
||||
if (classDef == null)
|
||||
{
|
||||
throw new InvalidTypeException(className);
|
||||
}
|
||||
ClassDefinition ofClassDef = getClass(ofClassName);
|
||||
if (ofClassDef == null)
|
||||
{
|
||||
throw new InvalidTypeException(ofClassName);
|
||||
}
|
||||
|
||||
// Only check if both ends are either a type or an aspect
|
||||
boolean subClassOf = false;
|
||||
if (classDef.isAspect() == ofClassDef.isAspect())
|
||||
{
|
||||
while (classDef != null)
|
||||
{
|
||||
if (classDef.equals(ofClassDef))
|
||||
{
|
||||
subClassOf = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// No match yet, so go to parent class
|
||||
QName parentClassName = classDef.getParentName();
|
||||
classDef = (parentClassName == null) ? null : getClass(parentClassName);
|
||||
}
|
||||
}
|
||||
return subClassOf;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getPropertyType(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public DataTypeDefinition getDataType(QName name)
|
||||
{
|
||||
return dictionaryDAO.getDataType(name);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.dictionary.DictionaryService#getDataType(java.lang.Class)
|
||||
*/
|
||||
public DataTypeDefinition getDataType(Class javaClass)
|
||||
{
|
||||
return dictionaryDAO.getDataType(javaClass);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getType(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public TypeDefinition getType(QName name)
|
||||
{
|
||||
return dictionaryDAO.getType(name);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getAspect(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public AspectDefinition getAspect(QName name)
|
||||
{
|
||||
return dictionaryDAO.getAspect(name);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getClass(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public ClassDefinition getClass(QName name)
|
||||
{
|
||||
return dictionaryDAO.getClass(name);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getAnonymousType(org.alfresco.repo.ref.QName, java.util.Collection)
|
||||
*/
|
||||
public TypeDefinition getAnonymousType(QName type, Collection<QName> aspects)
|
||||
{
|
||||
return dictionaryDAO.getAnonymousType(type, aspects);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getProperty(org.alfresco.repo.ref.QName, org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public PropertyDefinition getProperty(QName className, QName propertyName)
|
||||
{
|
||||
PropertyDefinition propDef = null;
|
||||
ClassDefinition classDef = dictionaryDAO.getClass(className);
|
||||
if (classDef != null)
|
||||
{
|
||||
Map<QName,PropertyDefinition> propDefs = classDef.getProperties();
|
||||
propDef = propDefs.get(propertyName);
|
||||
}
|
||||
return propDef;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getProperty(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public PropertyDefinition getProperty(QName propertyName)
|
||||
{
|
||||
return dictionaryDAO.getProperty(propertyName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getAssociation(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public AssociationDefinition getAssociation(QName associationName)
|
||||
{
|
||||
return dictionaryDAO.getAssociation(associationName);
|
||||
}
|
||||
|
||||
}
|
82
source/java/org/alfresco/repo/dictionary/DictionaryDAO.java
Normal file
82
source/java/org/alfresco/repo/dictionary/DictionaryDAO.java
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Dictionary Data Access
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public interface DictionaryDAO extends ModelQuery
|
||||
{
|
||||
|
||||
/**
|
||||
* @return the models known by the dictionary
|
||||
*/
|
||||
public Collection<QName> getModels();
|
||||
|
||||
/**
|
||||
* @param name the model to retrieve
|
||||
* @return the named model definition
|
||||
*/
|
||||
public ModelDefinition getModel(QName name);
|
||||
|
||||
/**
|
||||
* @param model the model to retrieve property types for
|
||||
* @return the property types of the model
|
||||
*/
|
||||
public Collection<DataTypeDefinition> getDataTypes(QName model);
|
||||
|
||||
/**
|
||||
* @param model the model to retrieve types for
|
||||
* @return the types of the model
|
||||
*/
|
||||
public Collection<TypeDefinition> getTypes(QName model);
|
||||
|
||||
/**
|
||||
* @param model the model to retrieve aspects for
|
||||
* @return the aspects of the model
|
||||
*/
|
||||
public Collection<AspectDefinition> getAspects(QName model);
|
||||
|
||||
/**
|
||||
* Construct an anonymous type that combines a primary type definition and
|
||||
* and one or more aspects
|
||||
*
|
||||
* @param type the primary type
|
||||
* @param aspects the aspects to combine
|
||||
* @return the anonymous type definition
|
||||
*/
|
||||
public TypeDefinition getAnonymousType(QName type, Collection<QName> aspects);
|
||||
|
||||
/**
|
||||
* Adds a model to the dictionary. The model is compiled and validated.
|
||||
*
|
||||
* @param model the model to add
|
||||
*/
|
||||
public void putModel(M2Model model);
|
||||
|
||||
}
|
288
source/java/org/alfresco/repo/dictionary/DictionaryDAOImpl.java
Normal file
288
source/java/org/alfresco/repo/dictionary/DictionaryDAOImpl.java
Normal file
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Default implementation of the Dictionary.
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public class DictionaryDAOImpl implements DictionaryDAO
|
||||
{
|
||||
// TODO: Allow for the dynamic creation of models. Supporting
|
||||
// this requires the ability to persistently store the
|
||||
// registration of models, the ability to load models
|
||||
// from a persistent store, the refresh of the cache
|
||||
// and concurrent read/write of the models.
|
||||
|
||||
// Namespace Data Access
|
||||
private NamespaceDAO namespaceDAO;
|
||||
|
||||
// Map of namespace to model name
|
||||
private Map<String,QName> namespaceToModel = new HashMap<String,QName>();
|
||||
|
||||
// Map of model name to compiled model
|
||||
private Map<QName,CompiledModel> compiledModels = new HashMap<QName,CompiledModel>();
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param namespaceDAO namespace data access
|
||||
*/
|
||||
public DictionaryDAOImpl(NamespaceDAO namespaceDAO)
|
||||
{
|
||||
this.namespaceDAO = namespaceDAO;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.DictionaryDAO#putModel(org.alfresco.repo.dictionary.impl.M2Model)
|
||||
*/
|
||||
public void putModel(M2Model model)
|
||||
{
|
||||
// Compile model definition
|
||||
CompiledModel compiledModel = model.compile(this, namespaceDAO);
|
||||
QName modelName = compiledModel.getModelDefinition().getName();
|
||||
|
||||
// Remove namespace definitions for previous model, if it exists
|
||||
CompiledModel previousVersion = compiledModels.get(modelName);
|
||||
if (previousVersion != null)
|
||||
{
|
||||
for (M2Namespace namespace : previousVersion.getM2Model().getNamespaces())
|
||||
{
|
||||
namespaceDAO.removePrefix(namespace.getPrefix());
|
||||
namespaceDAO.removeURI(namespace.getUri());
|
||||
namespaceToModel.remove(namespace.getUri());
|
||||
}
|
||||
}
|
||||
|
||||
// Create namespace definitions for new model
|
||||
for (M2Namespace namespace : model.getNamespaces())
|
||||
{
|
||||
namespaceDAO.addURI(namespace.getUri());
|
||||
namespaceDAO.addPrefix(namespace.getPrefix(), namespace.getUri());
|
||||
namespaceToModel.put(namespace.getUri(), modelName);
|
||||
}
|
||||
|
||||
// Publish new Model Definition
|
||||
compiledModels.put(modelName, compiledModel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param uri the namespace uri
|
||||
* @return the compiled model which defines the specified namespace
|
||||
*/
|
||||
private CompiledModel getCompiledModelForNamespace(String uri)
|
||||
{
|
||||
QName modelName = namespaceToModel.get(uri);
|
||||
return (modelName == null) ? null : getCompiledModel(modelName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param modelName the model name
|
||||
* @return the compiled model of the given name
|
||||
*/
|
||||
private CompiledModel getCompiledModel(QName modelName)
|
||||
{
|
||||
CompiledModel model = compiledModels.get(modelName);
|
||||
if (model == null)
|
||||
{
|
||||
// TODO: Load model from persistent store
|
||||
throw new DictionaryException("Model " + modelName + " does not exist");
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getPropertyType(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public DataTypeDefinition getDataType(QName typeName)
|
||||
{
|
||||
CompiledModel model = getCompiledModelForNamespace(typeName.getNamespaceURI());
|
||||
return (model == null) ? null : model.getDataType(typeName);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ModelQuery#getDataType(java.lang.Class)
|
||||
*/
|
||||
public DataTypeDefinition getDataType(Class javaClass)
|
||||
{
|
||||
for (CompiledModel model : compiledModels.values())
|
||||
{
|
||||
DataTypeDefinition dataTypeDef = model.getDataType(javaClass);
|
||||
if (dataTypeDef != null)
|
||||
{
|
||||
return dataTypeDef;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.DictionaryDAO#getPropertyTypes(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public Collection<DataTypeDefinition> getDataTypes(QName modelName)
|
||||
{
|
||||
CompiledModel model = getCompiledModel(modelName);
|
||||
return model.getDataTypes();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getType(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public TypeDefinition getType(QName typeName)
|
||||
{
|
||||
CompiledModel model = getCompiledModelForNamespace(typeName.getNamespaceURI());
|
||||
return (model == null) ? null : model.getType(typeName);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getAspect(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public AspectDefinition getAspect(QName aspectName)
|
||||
{
|
||||
CompiledModel model = getCompiledModelForNamespace(aspectName.getNamespaceURI());
|
||||
return (model == null) ? null : model.getAspect(aspectName);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getClass(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public ClassDefinition getClass(QName className)
|
||||
{
|
||||
CompiledModel model = getCompiledModelForNamespace(className.getNamespaceURI());
|
||||
return (model == null) ? null : model.getClass(className);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getProperty(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public PropertyDefinition getProperty(QName propertyName)
|
||||
{
|
||||
CompiledModel model = getCompiledModelForNamespace(propertyName.getNamespaceURI());
|
||||
return (model == null) ? null : model.getProperty(propertyName);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.ModelQuery#getAssociation(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public AssociationDefinition getAssociation(QName assocName)
|
||||
{
|
||||
CompiledModel model = getCompiledModelForNamespace(assocName.getNamespaceURI());
|
||||
return (model == null) ? null : model.getAssociation(assocName);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.DictionaryDAO#getModels()
|
||||
*/
|
||||
public Collection<QName> getModels()
|
||||
{
|
||||
return compiledModels.keySet();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.DictionaryDAO#getModel(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public ModelDefinition getModel(QName name)
|
||||
{
|
||||
CompiledModel model = getCompiledModel(name);
|
||||
if (model != null)
|
||||
{
|
||||
return model.getModelDefinition();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.DictionaryDAO#getTypes(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public Collection<TypeDefinition> getTypes(QName modelName)
|
||||
{
|
||||
CompiledModel model = getCompiledModel(modelName);
|
||||
return model.getTypes();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.DictionaryDAO#getAspects(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
public Collection<AspectDefinition> getAspects(QName modelName)
|
||||
{
|
||||
CompiledModel model = getCompiledModel(modelName);
|
||||
return model.getAspects();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.DictionaryDAO#getAnonymousType(org.alfresco.repo.ref.QName, java.util.Collection)
|
||||
*/
|
||||
public TypeDefinition getAnonymousType(QName type, Collection<QName> aspects)
|
||||
{
|
||||
TypeDefinition typeDef = getType(type);
|
||||
if (typeDef == null)
|
||||
{
|
||||
throw new DictionaryException("Failed to create anonymous type as specified type " + type + " not found");
|
||||
}
|
||||
Collection<AspectDefinition> aspectDefs = new ArrayList<AspectDefinition>();
|
||||
if (aspects != null)
|
||||
{
|
||||
for (QName aspect : aspects)
|
||||
{
|
||||
AspectDefinition aspectDef = getAspect(aspect);
|
||||
if (typeDef == null)
|
||||
{
|
||||
throw new DictionaryException("Failed to create anonymous type as specified aspect " + aspect + " not found");
|
||||
}
|
||||
aspectDefs.add(aspectDef);
|
||||
}
|
||||
}
|
||||
return new M2AnonymousTypeDefinition(typeDef, aspectDefs);
|
||||
}
|
||||
|
||||
|
||||
}
|
153
source/java/org/alfresco/repo/dictionary/DictionaryDAOTest.java
Normal file
153
source/java/org/alfresco/repo/dictionary/DictionaryDAOTest.java
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.InvalidTypeException;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
public class DictionaryDAOTest extends TestCase
|
||||
{
|
||||
|
||||
private static final String TEST_MODEL = "org/alfresco/repo/dictionary/dictionarydaotest_model.xml";
|
||||
private static final String TEST_BUNDLE = "org/alfresco/repo/dictionary/dictionarydaotest_model";
|
||||
private DictionaryService service;
|
||||
|
||||
|
||||
@Override
|
||||
public void setUp()
|
||||
{
|
||||
// Instantiate Dictionary Service
|
||||
NamespaceDAO namespaceDAO = new NamespaceDAOImpl();
|
||||
DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl(namespaceDAO);
|
||||
|
||||
// Populate with appropriate models
|
||||
DictionaryBootstrap bootstrap = new DictionaryBootstrap();
|
||||
List<String> bootstrapModels = new ArrayList<String>();
|
||||
bootstrapModels.add("alfresco/model/dictionaryModel.xml");
|
||||
bootstrapModels.add(TEST_MODEL);
|
||||
List<String> labels = new ArrayList<String>();
|
||||
labels.add(TEST_BUNDLE);
|
||||
bootstrap.setModels(bootstrapModels);
|
||||
bootstrap.setLabels(labels);
|
||||
bootstrap.setDictionaryDAO(dictionaryDAO);
|
||||
bootstrap.bootstrap();
|
||||
|
||||
DictionaryComponent component = new DictionaryComponent();
|
||||
component.setDictionaryDAO(dictionaryDAO);
|
||||
service = component;
|
||||
}
|
||||
|
||||
|
||||
public void testBootstrap()
|
||||
{
|
||||
NamespaceDAO namespaceDAO = new NamespaceDAOImpl();
|
||||
DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl(namespaceDAO);
|
||||
|
||||
DictionaryBootstrap bootstrap = new DictionaryBootstrap();
|
||||
List<String> bootstrapModels = new ArrayList<String>();
|
||||
|
||||
bootstrapModels.add("alfresco/model/dictionaryModel.xml");
|
||||
bootstrapModels.add("alfresco/model/systemModel.xml");
|
||||
bootstrapModels.add("alfresco/model/contentModel.xml");
|
||||
bootstrapModels.add("alfresco/model/applicationModel.xml");
|
||||
|
||||
bootstrapModels.add("alfresco/extension/exampleModel.xml");
|
||||
|
||||
bootstrapModels.add("org/alfresco/repo/security/authentication/userModel.xml");
|
||||
bootstrapModels.add("org/alfresco/repo/action/actionModel.xml");
|
||||
bootstrapModels.add("org/alfresco/repo/rule/ruleModel.xml");
|
||||
bootstrapModels.add("org/alfresco/repo/version/version_model.xml");
|
||||
|
||||
bootstrap.setModels(bootstrapModels);
|
||||
bootstrap.setDictionaryDAO(dictionaryDAO);
|
||||
bootstrap.bootstrap();
|
||||
}
|
||||
|
||||
|
||||
public void testLabels()
|
||||
{
|
||||
QName model = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "dictionarydaotest");
|
||||
ModelDefinition modelDef = service.getModel(model);
|
||||
assertEquals("Model Description", modelDef.getDescription());
|
||||
QName type = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "base");
|
||||
TypeDefinition typeDef = service.getType(type);
|
||||
assertEquals("Base Title", typeDef.getTitle());
|
||||
assertEquals("Base Description", typeDef.getDescription());
|
||||
QName prop = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "prop1");
|
||||
PropertyDefinition propDef = service.getProperty(prop);
|
||||
assertEquals("Prop1 Title", propDef.getTitle());
|
||||
assertEquals("Prop1 Description", propDef.getDescription());
|
||||
QName assoc = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "assoc1");
|
||||
AssociationDefinition assocDef = service.getAssociation(assoc);
|
||||
assertEquals("Assoc1 Title", assocDef.getTitle());
|
||||
assertEquals("Assoc1 Description", assocDef.getDescription());
|
||||
QName datatype = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "datatype");
|
||||
DataTypeDefinition datatypeDef = service.getDataType(datatype);
|
||||
assertEquals("Datatype Analyser", datatypeDef.getAnalyserClassName());
|
||||
}
|
||||
|
||||
|
||||
public void testSubClassOf()
|
||||
{
|
||||
QName invalid = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "invalid");
|
||||
QName base = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "base");
|
||||
QName file = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "file");
|
||||
QName folder = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "folder");
|
||||
QName referenceable = QName.createQName("http://www.alfresco.org/test/dictionarydaotest/1.0", "referenceable");
|
||||
|
||||
// Test invalid args
|
||||
try
|
||||
{
|
||||
service.isSubClass(invalid, referenceable);
|
||||
fail("Failed to catch invalid class parameter");
|
||||
}
|
||||
catch(InvalidTypeException e) {}
|
||||
|
||||
try
|
||||
{
|
||||
service.isSubClass(referenceable, invalid);
|
||||
fail("Failed to catch invalid class parameter");
|
||||
}
|
||||
catch(InvalidTypeException e) {}
|
||||
|
||||
// Test various flavours of subclassof
|
||||
boolean test1 = service.isSubClass(file, referenceable); // type vs aspect
|
||||
assertFalse(test1);
|
||||
boolean test2 = service.isSubClass(file, folder); // seperate hierarchies
|
||||
assertFalse(test2);
|
||||
boolean test3 = service.isSubClass(file, file); // self
|
||||
assertTrue(test3);
|
||||
boolean test4 = service.isSubClass(folder, base); // subclass
|
||||
assertTrue(test4);
|
||||
boolean test5 = service.isSubClass(base, folder); // reversed test
|
||||
assertFalse(test5);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
import org.alfresco.repo.transaction.TransactionListener;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
/**
|
||||
* Dictionary model type behaviour.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class DictionaryModelType
|
||||
{
|
||||
/** Key to the pending models */
|
||||
private static final String KEY_PENDING_MODELS = "dictionaryModelType.pendingModels";
|
||||
|
||||
/** The dictionary DAO */
|
||||
private DictionaryDAO dictionaryDAO;
|
||||
|
||||
/** The namespace DAO */
|
||||
private NamespaceDAO namespaceDAO;
|
||||
|
||||
/** The node service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/** The content service */
|
||||
private ContentService contentService;
|
||||
|
||||
/** The policy component */
|
||||
private PolicyComponent policyComponent;
|
||||
|
||||
/** Transaction listener */
|
||||
private DictionaryModelTypeTransactionListener transactionListener;
|
||||
|
||||
/**
|
||||
* Set the dictionary DAO
|
||||
*
|
||||
* @param dictionaryDAO the dictionary DAO
|
||||
*/
|
||||
public void setDictionaryDAO(DictionaryDAO dictionaryDAO)
|
||||
{
|
||||
this.dictionaryDAO = dictionaryDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the namespace DOA
|
||||
*
|
||||
* @param namespaceDAO the namespace DAO
|
||||
*/
|
||||
public void setNamespaceDAO(NamespaceDAO namespaceDAO)
|
||||
{
|
||||
this.namespaceDAO = namespaceDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the node service
|
||||
*
|
||||
* @param nodeService the node service
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content service
|
||||
*
|
||||
* @param contentService the content service
|
||||
*/
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the policy component
|
||||
*
|
||||
* @param policyComponent the policy component
|
||||
*/
|
||||
public void setPolicyComponent(PolicyComponent policyComponent)
|
||||
{
|
||||
this.policyComponent = policyComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* The initialise method
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
// Register interest in the onContentUpdate policy for the dictionary model type
|
||||
policyComponent.bindClassBehaviour(
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "onContentUpdate"),
|
||||
ContentModel.TYPE_DICTIONARY_MODEL,
|
||||
new JavaBehaviour(this, "onContentUpdate"));
|
||||
|
||||
// Create the transaction listener
|
||||
this.transactionListener = new DictionaryModelTypeTransactionListener(this.nodeService, this.contentService);
|
||||
}
|
||||
|
||||
/**
|
||||
* On content update behaviour implementation
|
||||
*
|
||||
* @param nodeRef the node reference whose content has been updated
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void onContentUpdate(NodeRef nodeRef)
|
||||
{
|
||||
Set<NodeRef> pendingModelUpdates = (Set<NodeRef>)AlfrescoTransactionSupport.getResource(KEY_PENDING_MODELS);
|
||||
if (pendingModelUpdates == null)
|
||||
{
|
||||
pendingModelUpdates = new HashSet<NodeRef>();
|
||||
AlfrescoTransactionSupport.bindResource(KEY_PENDING_MODELS, pendingModelUpdates);
|
||||
}
|
||||
pendingModelUpdates.add(nodeRef);
|
||||
|
||||
AlfrescoTransactionSupport.bindListener(this.transactionListener);
|
||||
}
|
||||
|
||||
// TODO need to listen for a change in the modelActive attribute and update appropriatly
|
||||
|
||||
// TODO need to listen for node deletion and act accordingly
|
||||
|
||||
/**
|
||||
* Dictionary model type transaction listener class.
|
||||
*/
|
||||
public class DictionaryModelTypeTransactionListener implements TransactionListener
|
||||
{
|
||||
/**
|
||||
* Id used in equals and hash
|
||||
*/
|
||||
private String id = GUID.generate();
|
||||
|
||||
private NodeService nodeService;
|
||||
private ContentService contentService;
|
||||
|
||||
public DictionaryModelTypeTransactionListener(NodeService nodeService, ContentService contentService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.transaction.TransactionListener#flush()
|
||||
*/
|
||||
public void flush()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.transaction.TransactionListener#beforeCommit(boolean)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void beforeCommit(boolean readOnly)
|
||||
{
|
||||
Set<NodeRef> pendingModels = (Set<NodeRef>)AlfrescoTransactionSupport.getResource(KEY_PENDING_MODELS);
|
||||
|
||||
if (pendingModels != null)
|
||||
{
|
||||
for (NodeRef nodeRef : pendingModels)
|
||||
{
|
||||
// Find out whether the model is active (by default it is)
|
||||
boolean isActive = true;
|
||||
Boolean value = (Boolean)nodeService.getProperty(nodeRef, ContentModel.PROP_MODEL_ACTIVE);
|
||||
if (value != null)
|
||||
{
|
||||
isActive = value.booleanValue();
|
||||
}
|
||||
|
||||
// Ignore if the node is a working copy or if its inactive
|
||||
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY) == false &&
|
||||
isActive == true)
|
||||
{
|
||||
// 1. Compile the model and update the details on the node
|
||||
// 2. Re-put the model
|
||||
|
||||
ContentReader contentReader = this.contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
|
||||
if (contentReader != null)
|
||||
{
|
||||
// Create a model from the current content
|
||||
M2Model m2Model = M2Model.createModel(contentReader.getContentInputStream());
|
||||
// TODO what do we do if we don't have a model??
|
||||
|
||||
// Try and compile the model
|
||||
ModelDefinition modelDefintion = m2Model.compile(dictionaryDAO, namespaceDAO).getModelDefinition();
|
||||
// TODO what do we do if the model does not compile
|
||||
|
||||
// Update the meta data for the model
|
||||
Map<QName, Serializable> props = this.nodeService.getProperties(nodeRef);
|
||||
props.put(ContentModel.PROP_MODEL_NAME, modelDefintion.getName());
|
||||
props.put(ContentModel.PROP_MODEL_DESCRIPTION, modelDefintion.getDescription());
|
||||
props.put(ContentModel.PROP_MODEL_AUTHOR, modelDefintion.getAuthor());
|
||||
props.put(ContentModel.PROP_MODEL_PUBLISHED_DATE, modelDefintion.getPublishedDate());
|
||||
props.put(ContentModel.PROP_MODEL_VERSION, modelDefintion.getVersion());
|
||||
this.nodeService.setProperties(nodeRef, props);
|
||||
|
||||
// TODO how do we get the dependancies for this model ??
|
||||
|
||||
// Put the model
|
||||
dictionaryDAO.putModel(m2Model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.transaction.TransactionListener#beforeCompletion()
|
||||
*/
|
||||
public void beforeCompletion()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.transaction.TransactionListener#afterCommit()
|
||||
*/
|
||||
public void afterCommit()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.transaction.TransactionListener#afterRollback()
|
||||
*/
|
||||
public void afterRollback()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof DictionaryModelTypeTransactionListener)
|
||||
{
|
||||
DictionaryModelTypeTransactionListener that = (DictionaryModelTypeTransactionListener) obj;
|
||||
return (this.id.equals(that.id));
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.transaction.TransactionUtil;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.BaseAlfrescoSpringTest;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
|
||||
/**
|
||||
* Dictionary model type unit test
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
|
||||
{
|
||||
/** QName of the test model */
|
||||
private static final QName TEST_MODEL_ONE = QName.createQName("{http://www.alfresco.org/test/testmodel1/1.0}testModelOne");
|
||||
|
||||
/** Test model XML */
|
||||
public static final String MODEL_ONE_XML =
|
||||
"<model name='test1:testModelOne' xmlns='http://www.alfresco.org/model/dictionary/1.0'>" +
|
||||
|
||||
" <description>Test model one</description>" +
|
||||
" <author>Alfresco</author>" +
|
||||
" <published>2005-05-30</published>" +
|
||||
" <version>1.0</version>" +
|
||||
|
||||
" <imports>" +
|
||||
" <import uri='http://www.alfresco.org/model/dictionary/1.0' prefix='d'/>" +
|
||||
" </imports>" +
|
||||
|
||||
" <namespaces>" +
|
||||
" <namespace uri='http://www.alfresco.org/test/testmodel1/1.0' prefix='test1'/>" +
|
||||
" </namespaces>" +
|
||||
|
||||
" <types>" +
|
||||
|
||||
" <type name='test1:base'>" +
|
||||
" <title>Base</title>" +
|
||||
" <description>The Base Type</description>" +
|
||||
" <properties>" +
|
||||
" <property name='test1:prop1'>" +
|
||||
" <type>d:text</type>" +
|
||||
" </property>" +
|
||||
" </properties>" +
|
||||
" </type>" +
|
||||
|
||||
" </types>" +
|
||||
|
||||
"</model>";
|
||||
|
||||
public static final String MODEL_ONE_MODIFIED_XML =
|
||||
"<model name='test1:testModelOne' xmlns='http://www.alfresco.org/model/dictionary/1.0'>" +
|
||||
|
||||
" <description>Test model one (updated)</description>" +
|
||||
" <author>Alfresco</author>" +
|
||||
" <published>2005-05-30</published>" +
|
||||
" <version>1.1</version>" +
|
||||
|
||||
" <imports>" +
|
||||
" <import uri='http://www.alfresco.org/model/dictionary/1.0' prefix='d'/>" +
|
||||
" </imports>" +
|
||||
|
||||
" <namespaces>" +
|
||||
" <namespace uri='http://www.alfresco.org/test/testmodel1/1.0' prefix='test1'/>" +
|
||||
" </namespaces>" +
|
||||
|
||||
" <types>" +
|
||||
|
||||
" <type name='test1:base'>" +
|
||||
" <title>Base</title>" +
|
||||
" <description>The Base Type</description>" +
|
||||
" <properties>" +
|
||||
" <property name='test1:prop1'>" +
|
||||
" <type>d:text</type>" +
|
||||
" </property>" +
|
||||
" <property name='test1:prop2'>" +
|
||||
" <type>d:text</type>" +
|
||||
" </property>" +
|
||||
" </properties>" +
|
||||
" </type>" +
|
||||
|
||||
" </types>" +
|
||||
|
||||
"</model>";
|
||||
|
||||
/** Services used in tests */
|
||||
private DictionaryService dictionaryService;
|
||||
private NamespaceService namespaceService;
|
||||
private CheckOutCheckInService cociService;
|
||||
|
||||
/**
|
||||
* On setup in transaction override
|
||||
*/
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
|
||||
super.onSetUpInTransaction();
|
||||
|
||||
// Get the required services
|
||||
this.dictionaryService = (DictionaryService)this.applicationContext.getBean("dictionaryService");
|
||||
this.namespaceService = (NamespaceService)this.applicationContext.getBean("namespaceService");
|
||||
this.cociService = (CheckOutCheckInService)this.applicationContext.getBean("checkOutCheckInService");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the creation of dictionary model nodes
|
||||
*/
|
||||
public void testCreateAndUpdateDictionaryModelNodeContent()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Check that the model has not yet been loaded into the dictionary
|
||||
this.dictionaryService.getModel(TEST_MODEL_ONE);
|
||||
fail("This model has not yet been loaded into the dictionary service");
|
||||
}
|
||||
catch (DictionaryException exception)
|
||||
{
|
||||
// We expect this exception
|
||||
}
|
||||
|
||||
// Check that the namespace is not yet in the namespace service
|
||||
String uri = this.namespaceService.getNamespaceURI("test1");
|
||||
assertNull(uri);
|
||||
|
||||
// Create a model node
|
||||
PropertyMap properties = new PropertyMap(1);
|
||||
properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
|
||||
final NodeRef modelNode = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "dictionaryModels"),
|
||||
ContentModel.TYPE_DICTIONARY_MODEL,
|
||||
properties).getChildRef();
|
||||
assertNotNull(modelNode);
|
||||
|
||||
// Add the model content to the model node
|
||||
ContentWriter contentWriter = this.contentService.getWriter(modelNode, ContentModel.PROP_CONTENT, true);
|
||||
contentWriter.setEncoding("UTF-8");
|
||||
contentWriter.setMimetype(MimetypeMap.MIMETYPE_XML);
|
||||
contentWriter.putContent(MODEL_ONE_XML);
|
||||
|
||||
// End the transaction to force update
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
final NodeRef workingCopy = TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<NodeRef>()
|
||||
{
|
||||
public NodeRef doWork() throws Exception
|
||||
{
|
||||
// Check that the meta data has been extracted from the model
|
||||
assertEquals(QName.createQName("{http://www.alfresco.org/test/testmodel1/1.0}testModelOne"),
|
||||
DictionaryModelTypeTest.this.nodeService.getProperty(modelNode, ContentModel.PROP_MODEL_NAME));
|
||||
assertEquals("Test model one", DictionaryModelTypeTest.this.nodeService.getProperty(modelNode, ContentModel.PROP_MODEL_DESCRIPTION));
|
||||
assertEquals("Alfresco", DictionaryModelTypeTest.this.nodeService.getProperty(modelNode, ContentModel.PROP_MODEL_AUTHOR));
|
||||
//System.out.println(this.nodeService.getProperty(modelNode, ContentModel.PROP_MODEL_PUBLISHED_DATE));
|
||||
assertEquals("1.0", DictionaryModelTypeTest.this.nodeService.getProperty(modelNode, ContentModel.PROP_MODEL_VERSION));
|
||||
|
||||
// Check that the model is now available from the dictionary
|
||||
ModelDefinition modelDefinition2 = DictionaryModelTypeTest.this.dictionaryService.getModel(TEST_MODEL_ONE);
|
||||
assertNotNull(modelDefinition2);
|
||||
assertEquals("Test model one", modelDefinition2.getDescription());
|
||||
|
||||
// Check that the namespace has been added to the namespace service
|
||||
String uri2 = DictionaryModelTypeTest.this.namespaceService.getNamespaceURI("test1");
|
||||
assertEquals(uri2, "http://www.alfresco.org/test/testmodel1/1.0");
|
||||
|
||||
// Lets check the node out and update the content
|
||||
NodeRef workingCopy = DictionaryModelTypeTest.this.cociService.checkout(modelNode);
|
||||
ContentWriter contentWriter2 = DictionaryModelTypeTest.this.contentService.getWriter(workingCopy, ContentModel.PROP_CONTENT, true);
|
||||
contentWriter2.putContent(MODEL_ONE_MODIFIED_XML);
|
||||
|
||||
return workingCopy;
|
||||
}
|
||||
});
|
||||
|
||||
TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
// Check that the policy has not been fired since we have updated a working copy
|
||||
assertEquals("1.0", DictionaryModelTypeTest.this.nodeService.getProperty(workingCopy, ContentModel.PROP_MODEL_VERSION));
|
||||
|
||||
// Now check the model changed back in
|
||||
DictionaryModelTypeTest.this.cociService.checkin(workingCopy, null);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
// Now check that the model has been updated
|
||||
assertEquals("1.1", DictionaryModelTypeTest.this.nodeService.getProperty(modelNode, ContentModel.PROP_MODEL_VERSION));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
|
||||
|
||||
/**
|
||||
* Data Dictionary Namespace Service Implementation
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class DictionaryNamespaceComponent implements NamespaceService
|
||||
{
|
||||
|
||||
/**
|
||||
* Namespace DAO
|
||||
*/
|
||||
private NamespaceDAO namespaceDAO;
|
||||
|
||||
|
||||
/**
|
||||
* Sets the Namespace DAO
|
||||
*
|
||||
* @param namespaceDAO namespace DAO
|
||||
*/
|
||||
public void setNamespaceDAO(NamespaceDAO namespaceDAO)
|
||||
{
|
||||
this.namespaceDAO = namespaceDAO;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.NamespaceService#getURIs()
|
||||
*/
|
||||
public Collection<String> getURIs()
|
||||
{
|
||||
return namespaceDAO.getURIs();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.NamespaceService#getPrefixes()
|
||||
*/
|
||||
public Collection<String> getPrefixes()
|
||||
{
|
||||
return namespaceDAO.getPrefixes();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.ref.NamespacePrefixResolver#getNamespaceURI(java.lang.String)
|
||||
*/
|
||||
public String getNamespaceURI(String prefix)
|
||||
{
|
||||
return namespaceDAO.getNamespaceURI(prefix);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.ref.NamespacePrefixResolver#getPrefixes(java.lang.String)
|
||||
*/
|
||||
public Collection<String> getPrefixes(String namespaceURI)
|
||||
{
|
||||
return namespaceDAO.getPrefixes(namespaceURI);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.namespace.NamespaceService#registerNamespace(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void registerNamespace(String prefix, String uri)
|
||||
{
|
||||
// TODO:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.namespace.NamespaceService#registerNamespace(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void unregisterNamespace(String prefix)
|
||||
{
|
||||
// TODO:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,296 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.transaction.TransactionUtil;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
|
||||
|
||||
/**
|
||||
* Bootstrap the dictionary from specified locations within the repository
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class DictionaryRepositoryBootstrap
|
||||
{
|
||||
/** Loactions in the respository fro which models should be loaded */
|
||||
private List<RepositoryLocation> repositoryLocations = new ArrayList<RepositoryLocation>();
|
||||
|
||||
/** Dictionary DAO */
|
||||
private DictionaryDAO dictionaryDAO = null;
|
||||
|
||||
/** Search service */
|
||||
private SearchService searchService;
|
||||
|
||||
/** The content service */
|
||||
private ContentService contentService;
|
||||
|
||||
/** The transaction service */
|
||||
private TransactionService transactionService;
|
||||
|
||||
/** The authentication component */
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
|
||||
/**
|
||||
* Sets the Dictionary DAO
|
||||
*
|
||||
* @param dictionaryDAO
|
||||
*/
|
||||
public void setDictionaryDAO(DictionaryDAO dictionaryDAO)
|
||||
{
|
||||
this.dictionaryDAO = dictionaryDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the search search service
|
||||
*
|
||||
* @param searchService the search service
|
||||
*/
|
||||
public void setSearchService(SearchService searchService)
|
||||
{
|
||||
this.searchService = searchService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content service
|
||||
*
|
||||
* @param contentService the content service
|
||||
*/
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the transaction service
|
||||
*
|
||||
* @param transactionService the transaction service
|
||||
*/
|
||||
public void setTransactionService(TransactionService transactionService)
|
||||
{
|
||||
this.transactionService = transactionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the authentication service
|
||||
*
|
||||
* @param authenticationComponent the authentication component
|
||||
*/
|
||||
public void setAuthenticationComponent(
|
||||
AuthenticationComponent authenticationComponent)
|
||||
{
|
||||
this.authenticationComponent = authenticationComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the respository locations
|
||||
*
|
||||
* @param repositoryLocations list of the repository locaitons
|
||||
*/
|
||||
public void setRepositoryLocations(
|
||||
List<RepositoryLocation> repositoryLocations)
|
||||
{
|
||||
this.repositoryLocations = repositoryLocations;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void bootstrap()
|
||||
{
|
||||
TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
DictionaryRepositoryBootstrap.this.authenticationComponent.setCurrentUser(
|
||||
DictionaryRepositoryBootstrap.this.authenticationComponent.getSystemUserName());
|
||||
try
|
||||
{
|
||||
bootstrapImpl();
|
||||
}
|
||||
finally
|
||||
{
|
||||
DictionaryRepositoryBootstrap.this.authenticationComponent.clearCurrentSecurityContext();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap the Dictionary
|
||||
*/
|
||||
public void bootstrapImpl()
|
||||
{
|
||||
Map<String, M2Model> modelMap = new HashMap<String, M2Model>();
|
||||
|
||||
// Register the models found in the respository
|
||||
for (RepositoryLocation repositoryLocation : this.repositoryLocations)
|
||||
{
|
||||
ResultSet resultSet = this.searchService.query(repositoryLocation.getStoreRef(), SearchService.LANGUAGE_LUCENE, repositoryLocation.getQueryStatement());
|
||||
for (NodeRef dictionaryModel : resultSet.getNodeRefs())
|
||||
{
|
||||
M2Model model = createM2Model(dictionaryModel);
|
||||
if (model != null)
|
||||
{
|
||||
for (M2Namespace namespace : model.getNamespaces())
|
||||
{
|
||||
modelMap.put(namespace.getUri(), model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load the models ensuring that they are loaded in the correct order
|
||||
List<String> loadedModels = new ArrayList<String>();
|
||||
for (Map.Entry<String, M2Model> entry : modelMap.entrySet())
|
||||
{
|
||||
loadModel(modelMap, loadedModels, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a model (and it dependants) if it does not exist in the list of loaded models.
|
||||
*
|
||||
* @param modelMap a map of the models to be loaded
|
||||
* @param loadedModels the list of models already loaded
|
||||
* @param model the model to try and load
|
||||
*/
|
||||
private void loadModel(Map<String, M2Model> modelMap, List<String> loadedModels, M2Model model)
|
||||
{
|
||||
String modelName = model.getName();
|
||||
if (loadedModels.contains(modelName) == false)
|
||||
{
|
||||
for (M2Namespace importNamespace : model.getImports())
|
||||
{
|
||||
M2Model importedModel = modelMap.get(importNamespace.getUri());
|
||||
if (importedModel != null)
|
||||
{
|
||||
// Ensure that the imported model is loaded first
|
||||
loadModel(modelMap, loadedModels, importedModel);
|
||||
}
|
||||
// else we can assume that the imported model is already loaded, if this not the case then
|
||||
// an error will be raised during compilation
|
||||
}
|
||||
|
||||
dictionaryDAO.putModel(model);
|
||||
loadedModels.add(modelName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a M2Model from a dictionary model node
|
||||
*
|
||||
* @param nodeRef the dictionary model node reference
|
||||
* @return the M2Model
|
||||
*/
|
||||
public M2Model createM2Model(NodeRef nodeRef)
|
||||
{
|
||||
M2Model model = null;
|
||||
ContentReader contentReader = this.contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
|
||||
if (contentReader != null)
|
||||
{
|
||||
model = M2Model.createModel(contentReader.getContentInputStream());
|
||||
}
|
||||
// TODO should we inactivate the model node and put the error somewhere??
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Repositotry location object, defines a location in the repository from within which dictionary models should be loaded
|
||||
* for inclusion in the data dictionary.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class RepositoryLocation
|
||||
{
|
||||
/** Store protocol */
|
||||
private String storeProtocol;
|
||||
|
||||
/** Store identifier */
|
||||
private String storeId;
|
||||
|
||||
/** Path */
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* Set the store protocol
|
||||
*
|
||||
* @param storeProtocol the store protocol
|
||||
*/
|
||||
public void setStoreProtocol(String storeProtocol)
|
||||
{
|
||||
this.storeProtocol = storeProtocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the store identifier
|
||||
*
|
||||
* @param storeId the store identifier
|
||||
*/
|
||||
public void setStoreId(String storeId)
|
||||
{
|
||||
this.storeId = storeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the path
|
||||
*
|
||||
* @param path the path
|
||||
*/
|
||||
public void setPath(String path)
|
||||
{
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the store reference
|
||||
*
|
||||
* @return the store reference
|
||||
*/
|
||||
public StoreRef getStoreRef()
|
||||
{
|
||||
return new StoreRef(this.storeProtocol, this.storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query statement, based on the path
|
||||
*
|
||||
* @return the query statement
|
||||
*/
|
||||
public String getQueryStatement()
|
||||
{
|
||||
String result = "+TYPE:\"" + ContentModel.TYPE_DICTIONARY_MODEL.toString() + "\"";
|
||||
if (this.path != null)
|
||||
{
|
||||
result += " +PATH:\"" + this.path + "\"";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,241 @@
|
||||
package org.alfresco.repo.dictionary;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.dictionary.DictionaryRepositoryBootstrap.RepositoryLocation;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.BaseAlfrescoSpringTest;
|
||||
|
||||
public class DictionaryRepositoryBootstrapTest extends BaseAlfrescoSpringTest
|
||||
{
|
||||
public static final String TEMPLATE_MODEL_XML =
|
||||
"<model name={0} xmlns=\"http://www.alfresco.org/model/dictionary/1.0\">" +
|
||||
|
||||
" <description>{1}</description>" +
|
||||
" <author>Alfresco</author>" +
|
||||
" <published>2005-05-30</published>" +
|
||||
" <version>1.0</version>" +
|
||||
|
||||
" <imports>" +
|
||||
" <import uri=\"http://www.alfresco.org/model/dictionary/1.0\" prefix=\"d\"/>" +
|
||||
" {2} " +
|
||||
" </imports>" +
|
||||
|
||||
" <namespaces>" +
|
||||
" <namespace uri={3} prefix={4}/>" +
|
||||
" </namespaces>" +
|
||||
|
||||
" <types>" +
|
||||
|
||||
" <type name={5}>" +
|
||||
" <title>Base</title>" +
|
||||
" <description>The Base Type</description>" +
|
||||
" <properties>" +
|
||||
" <property name={6}>" +
|
||||
" <type>d:text</type>" +
|
||||
" </property>" +
|
||||
" </properties>" +
|
||||
" </type>" +
|
||||
|
||||
" </types>" +
|
||||
|
||||
"</model>";
|
||||
|
||||
/** Behaviour filter */
|
||||
private BehaviourFilter behaviourFilter;
|
||||
|
||||
/** The bootstrap service */
|
||||
private DictionaryRepositoryBootstrap bootstrap;
|
||||
|
||||
/** The search service */
|
||||
private SearchService searchService;
|
||||
|
||||
/** The dictionary DAO */
|
||||
private DictionaryDAO dictionaryDAO;
|
||||
|
||||
/** The transaction service */
|
||||
private TransactionService transactionService;
|
||||
|
||||
/** The authentication service */
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
|
||||
/**
|
||||
* @see org.springframework.test.AbstractTransactionalSpringContextTests#onSetUpInTransaction()
|
||||
*/
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
super.onSetUpInTransaction();
|
||||
|
||||
// Get the behaviour filter and turn the behaviour off for the model type
|
||||
this.behaviourFilter = (BehaviourFilter)this.applicationContext.getBean("policyBehaviourFilter");
|
||||
this.behaviourFilter.disableBehaviour(ContentModel.TYPE_DICTIONARY_MODEL);
|
||||
|
||||
this.searchService = (SearchService)this.applicationContext.getBean("searchService");
|
||||
this.dictionaryDAO = (DictionaryDAO)this.applicationContext.getBean("dictionaryDAO");
|
||||
this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");
|
||||
this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
|
||||
|
||||
this.bootstrap = new DictionaryRepositoryBootstrap();
|
||||
this.bootstrap.setContentService(this.contentService);
|
||||
this.bootstrap.setSearchService(this.searchService);
|
||||
this.bootstrap.setDictionaryDAO(this.dictionaryDAO);
|
||||
this.bootstrap.setAuthenticationComponent(this.authenticationComponent);
|
||||
this.bootstrap.setTransactionService(this.transactionService);
|
||||
|
||||
RepositoryLocation location = this.bootstrap.new RepositoryLocation();
|
||||
location.setStoreProtocol(this.storeRef.getProtocol());
|
||||
location.setStoreId(this.storeRef.getIdentifier());
|
||||
// NOTE: we are not setting the path for now .. in doing so we are searching the whole dictionary
|
||||
|
||||
List<RepositoryLocation> locations = new ArrayList<RepositoryLocation>();
|
||||
locations.add(location);
|
||||
this.bootstrap.setRepositoryLocations(locations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test bootstrap
|
||||
*/
|
||||
public void testBootstrap()
|
||||
{
|
||||
createModelNode(
|
||||
"http://www.alfresco.org/model/test2DictionaryBootstrapFromRepo/1.0",
|
||||
"test2",
|
||||
"testModel2",
|
||||
" <import uri=\"http://www.alfresco.org/model/test1DictionaryBootstrapFromRepo/1.0\" prefix=\"test1\"/> ",
|
||||
"Test model two",
|
||||
"base2",
|
||||
"prop2");
|
||||
createModelNode(
|
||||
"http://www.alfresco.org/model/test3DictionaryBootstrapFromRepo/1.0",
|
||||
"test3",
|
||||
"testModel3",
|
||||
" <import uri=\"http://www.alfresco.org/model/test1DictionaryBootstrapFromRepo/1.0\" prefix=\"test1\"/> ",
|
||||
"Test model three",
|
||||
"base3",
|
||||
"prop3");
|
||||
createModelNode(
|
||||
"http://www.alfresco.org/model/test1DictionaryBootstrapFromRepo/1.0",
|
||||
"test1",
|
||||
"testModel1",
|
||||
"",
|
||||
"Test model one",
|
||||
"base1",
|
||||
"prop1");
|
||||
|
||||
// Check that the model is not in the dictionary yet
|
||||
try
|
||||
{
|
||||
this.dictionaryDAO.getModel(
|
||||
QName.createQName("http://www.alfresco.org/model/test1DictionaryBootstrapFromRepo/1.0", "testModel1"));
|
||||
fail("The model should not be there.");
|
||||
}
|
||||
catch (DictionaryException exception)
|
||||
{
|
||||
// Ignore since we where expecting this
|
||||
}
|
||||
|
||||
// Now do the bootstrap
|
||||
this.bootstrap.bootstrap();
|
||||
|
||||
// Check that the model is now there
|
||||
ModelDefinition modelDefinition1 = this.dictionaryDAO.getModel(
|
||||
QName.createQName("http://www.alfresco.org/model/test1DictionaryBootstrapFromRepo/1.0", "testModel1"));
|
||||
assertNotNull(modelDefinition1);
|
||||
ModelDefinition modelDefinition2 = this.dictionaryDAO.getModel(
|
||||
QName.createQName("http://www.alfresco.org/model/test2DictionaryBootstrapFromRepo/1.0", "testModel2"));
|
||||
assertNotNull(modelDefinition2);
|
||||
ModelDefinition modelDefinition3 = this.dictionaryDAO.getModel(
|
||||
QName.createQName("http://www.alfresco.org/model/test3DictionaryBootstrapFromRepo/1.0", "testModel3"));
|
||||
assertNotNull(modelDefinition3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create model node
|
||||
*
|
||||
* @param uri
|
||||
* @param prefix
|
||||
* @param modelLocalName
|
||||
* @param importStatement
|
||||
* @param description
|
||||
* @param typeName
|
||||
* @param propertyName
|
||||
* @return
|
||||
*/
|
||||
private NodeRef createModelNode(
|
||||
String uri,
|
||||
String prefix,
|
||||
String modelLocalName,
|
||||
String importStatement,
|
||||
String description,
|
||||
String typeName,
|
||||
String propertyName)
|
||||
{
|
||||
// Create a model node
|
||||
NodeRef model = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName("{test}models"),
|
||||
ContentModel.TYPE_DICTIONARY_MODEL).getChildRef();
|
||||
ContentWriter contentWriter1 = this.contentService.getWriter(model, ContentModel.PROP_CONTENT, true);
|
||||
contentWriter1.setEncoding("UTF-8");
|
||||
contentWriter1.setMimetype(MimetypeMap.MIMETYPE_XML);
|
||||
String modelOne = getModelString(
|
||||
uri,
|
||||
prefix,
|
||||
modelLocalName,
|
||||
importStatement,
|
||||
description,
|
||||
typeName,
|
||||
propertyName);
|
||||
contentWriter1.putContent(modelOne);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Gets the model string
|
||||
*
|
||||
* @param uri
|
||||
* @param prefix
|
||||
* @param modelLocalName
|
||||
* @param importStatement
|
||||
* @param description
|
||||
* @param typeName
|
||||
* @param propertyName
|
||||
* @return
|
||||
*/
|
||||
private String getModelString(
|
||||
String uri,
|
||||
String prefix,
|
||||
String modelLocalName,
|
||||
String importStatement,
|
||||
String description,
|
||||
String typeName,
|
||||
String propertyName)
|
||||
{
|
||||
return MessageFormat.format(
|
||||
TEMPLATE_MODEL_XML,
|
||||
new Object[]{
|
||||
"'" + prefix +":" + modelLocalName + "'",
|
||||
description,
|
||||
importStatement,
|
||||
"'" + uri + "'",
|
||||
"'" + prefix + "'",
|
||||
"'" + prefix + ":" + typeName + "'",
|
||||
"'" + prefix + ":" + propertyName + "'"});
|
||||
}
|
||||
}
|
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Compiled anonymous type definition.
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
/*package*/ class M2AnonymousTypeDefinition implements TypeDefinition
|
||||
{
|
||||
private TypeDefinition type;
|
||||
private Map<QName,PropertyDefinition> properties = new HashMap<QName,PropertyDefinition>();
|
||||
private Map<QName,AssociationDefinition> associations = new HashMap<QName,AssociationDefinition>();
|
||||
private Map<QName,ChildAssociationDefinition> childassociations = new HashMap<QName,ChildAssociationDefinition>();
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param type the primary type
|
||||
* @param aspects the aspects to combine with the type
|
||||
*/
|
||||
/*package*/ M2AnonymousTypeDefinition(TypeDefinition type, Collection<AspectDefinition> aspects)
|
||||
{
|
||||
this.type = type;
|
||||
|
||||
// Combine features of type and aspects
|
||||
properties.putAll(type.getProperties());
|
||||
associations.putAll(type.getAssociations());
|
||||
childassociations.putAll(type.getChildAssociations());
|
||||
for (AspectDefinition aspect : aspects)
|
||||
{
|
||||
properties.putAll(aspect.getProperties());
|
||||
associations.putAll(aspect.getAssociations());
|
||||
childassociations.putAll(aspect.getChildAssociations());
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.dictionary.ClassDefinition#getModel()
|
||||
*/
|
||||
public ModelDefinition getModel()
|
||||
{
|
||||
return type.getModel();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.TypeDefinition#getDefaultAspects()
|
||||
*/
|
||||
public List<AspectDefinition> getDefaultAspects()
|
||||
{
|
||||
return type.getDefaultAspects();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#getName()
|
||||
*/
|
||||
public QName getName()
|
||||
{
|
||||
return QName.createQName(NamespaceService.DICTIONARY_MODEL_1_0_URI, "anonymous#" + type.getName().getLocalName());
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#getTitle()
|
||||
*/
|
||||
public String getTitle()
|
||||
{
|
||||
return type.getTitle();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#getDescription()
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return type.getDescription();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#getParentName()
|
||||
*/
|
||||
public QName getParentName()
|
||||
{
|
||||
return type.getParentName();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#isAspect()
|
||||
*/
|
||||
public boolean isAspect()
|
||||
{
|
||||
return type.isAspect();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#getProperties()
|
||||
*/
|
||||
public Map<QName, PropertyDefinition> getProperties()
|
||||
{
|
||||
return Collections.unmodifiableMap(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.dictionary.ClassDefinition#getDefaultValues()
|
||||
*/
|
||||
public Map<QName, Serializable> getDefaultValues()
|
||||
{
|
||||
Map<QName, Serializable> result = new HashMap<QName, Serializable>(5);
|
||||
|
||||
for(Map.Entry<QName, PropertyDefinition> entry : properties.entrySet())
|
||||
{
|
||||
PropertyDefinition propertyDefinition = entry.getValue();
|
||||
String defaultValue = propertyDefinition.getDefaultValue();
|
||||
if (defaultValue != null)
|
||||
{
|
||||
result.put(entry.getKey(), defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.unmodifiableMap(result);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#getAssociations()
|
||||
*/
|
||||
public Map<QName, AssociationDefinition> getAssociations()
|
||||
{
|
||||
return Collections.unmodifiableMap(associations);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.dictionary.ClassDefinition#isContainer()
|
||||
*/
|
||||
public boolean isContainer()
|
||||
{
|
||||
return !childassociations.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#getChildAssociations()
|
||||
*/
|
||||
public Map<QName, ChildAssociationDefinition> getChildAssociations()
|
||||
{
|
||||
return Collections.unmodifiableMap(childassociations);
|
||||
}
|
||||
|
||||
}
|
32
source/java/org/alfresco/repo/dictionary/M2Aspect.java
Normal file
32
source/java/org/alfresco/repo/dictionary/M2Aspect.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
/**
|
||||
* Aspect definition.
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class M2Aspect extends M2Class
|
||||
{
|
||||
|
||||
/*package*/ M2Aspect()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Compiled Aspect Definition.
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
/*package*/ class M2AspectDefinition extends M2ClassDefinition
|
||||
implements AspectDefinition
|
||||
{
|
||||
|
||||
/*package*/ M2AspectDefinition(ModelDefinition model, M2Aspect m2Aspect, NamespacePrefixResolver resolver, Map<QName, PropertyDefinition> modelProperties, Map<QName, AssociationDefinition> modelAssociations)
|
||||
{
|
||||
super(model, m2Aspect, resolver, modelProperties, modelAssociations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription()
|
||||
{
|
||||
String value = M2Label.getLabel(model, "aspect", name, "description");
|
||||
|
||||
// if we don't have a description call the super class
|
||||
if (value == null)
|
||||
{
|
||||
value = super.getDescription();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle()
|
||||
{
|
||||
String value = M2Label.getLabel(model, "aspect", name, "title");
|
||||
|
||||
// if we don't have a title call the super class
|
||||
if (value == null)
|
||||
{
|
||||
value = super.getTitle();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
37
source/java/org/alfresco/repo/dictionary/M2Association.java
Normal file
37
source/java/org/alfresco/repo/dictionary/M2Association.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
|
||||
/**
|
||||
* Association definition.
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class M2Association extends M2ClassAssociation
|
||||
{
|
||||
|
||||
/*package*/ M2Association()
|
||||
{
|
||||
}
|
||||
|
||||
/*package*/ M2Association(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Compiled Association Definition.
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
/*package*/ class M2AssociationDefinition implements AssociationDefinition
|
||||
{
|
||||
|
||||
private ClassDefinition classDef;
|
||||
private M2ClassAssociation assoc;
|
||||
private QName name;
|
||||
private QName targetClassName;
|
||||
private ClassDefinition targetClass;
|
||||
private QName sourceRoleName;
|
||||
private QName targetRoleName;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param m2Association association definition
|
||||
* @return the definition
|
||||
*/
|
||||
/*package*/ M2AssociationDefinition(ClassDefinition classDef, M2ClassAssociation assoc, NamespacePrefixResolver resolver)
|
||||
{
|
||||
this.classDef = classDef;
|
||||
this.assoc = assoc;
|
||||
|
||||
// Resolve names
|
||||
this.name = QName.createQName(assoc.getName(), resolver);
|
||||
this.targetClassName = QName.createQName(assoc.getTargetClassName(), resolver);
|
||||
this.sourceRoleName = QName.createQName(assoc.getSourceRoleName(), resolver);
|
||||
this.targetRoleName = QName.createQName(assoc.getTargetRoleName(), resolver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(56);
|
||||
sb.append("Association")
|
||||
.append("[ class=").append(classDef)
|
||||
.append(", name=").append(name)
|
||||
.append(", target class=").append(targetClassName)
|
||||
.append(", source role=").append(sourceRoleName)
|
||||
.append(", target role=").append(targetRoleName)
|
||||
.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/*package*/ M2ClassAssociation getM2Association()
|
||||
{
|
||||
return assoc;
|
||||
}
|
||||
|
||||
|
||||
/*package*/ void resolveDependencies(ModelQuery query)
|
||||
{
|
||||
if (targetClassName == null)
|
||||
{
|
||||
throw new DictionaryException("Target class of association " + name.toPrefixString() + " must be specified");
|
||||
}
|
||||
targetClass = query.getClass(targetClassName);
|
||||
if (targetClass == null)
|
||||
{
|
||||
throw new DictionaryException("Target class " + targetClassName.toPrefixString() + " of association " + name.toPrefixString() + " is not found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.dictionary.AssociationDefinition#getModel()
|
||||
*/
|
||||
public ModelDefinition getModel()
|
||||
{
|
||||
return classDef.getModel();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.AssociationDefinition#getName()
|
||||
*/
|
||||
public QName getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.AssociationDefinition#isChild()
|
||||
*/
|
||||
public boolean isChild()
|
||||
{
|
||||
return (assoc instanceof M2ChildAssociation);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.AssociationDefinition#getTitle()
|
||||
*/
|
||||
public String getTitle()
|
||||
{
|
||||
String value = M2Label.getLabel(classDef.getModel(), "association", name, "title");
|
||||
if (value == null)
|
||||
{
|
||||
value = assoc.getTitle();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.AssociationDefinition#getDescription()
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
String value = M2Label.getLabel(classDef.getModel(), "association", name, "description");
|
||||
if (value == null)
|
||||
{
|
||||
value = assoc.getDescription();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.AssociationDefinition#isProtected()
|
||||
*/
|
||||
public boolean isProtected()
|
||||
{
|
||||
return assoc.isProtected();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.AssociationDefinition#getSourceClass()
|
||||
*/
|
||||
public ClassDefinition getSourceClass()
|
||||
{
|
||||
return classDef;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.AssociationDefinition#getSourceRoleName()
|
||||
*/
|
||||
public QName getSourceRoleName()
|
||||
{
|
||||
return sourceRoleName;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.AssociationDefinition#isSourceMandatory()
|
||||
*/
|
||||
public boolean isSourceMandatory()
|
||||
{
|
||||
return assoc.isSourceMandatory();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.AssociationDefinition#isSourceMany()
|
||||
*/
|
||||
public boolean isSourceMany()
|
||||
{
|
||||
return assoc.isSourceMany();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.AssociationDefinition#getTargetClass()
|
||||
*/
|
||||
public ClassDefinition getTargetClass()
|
||||
{
|
||||
return targetClass;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.AssociationDefinition#getTargetRoleName()
|
||||
*/
|
||||
public QName getTargetRoleName()
|
||||
{
|
||||
return targetRoleName;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.AssociationDefinition#isTargetMandatory()
|
||||
*/
|
||||
public boolean isTargetMandatory()
|
||||
{
|
||||
return assoc.isTargetMandatory();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.AssociationDefinition#isTargetMany()
|
||||
*/
|
||||
public boolean isTargetMany()
|
||||
{
|
||||
return assoc.isTargetMany();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
|
||||
/**
|
||||
* Child Association definition.
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public class M2ChildAssociation extends M2ClassAssociation
|
||||
{
|
||||
private String requiredChildName = null;
|
||||
private Boolean allowDuplicateChildName = null;
|
||||
|
||||
|
||||
/*package*/ M2ChildAssociation()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*package*/ M2ChildAssociation(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
|
||||
public String getRequiredChildName()
|
||||
{
|
||||
return requiredChildName;
|
||||
}
|
||||
|
||||
|
||||
public void setRequiredChildName(String requiredChildName)
|
||||
{
|
||||
this.requiredChildName = requiredChildName;
|
||||
}
|
||||
|
||||
|
||||
public boolean allowDuplicateChildName()
|
||||
{
|
||||
return allowDuplicateChildName == null ? true : allowDuplicateChildName;
|
||||
}
|
||||
|
||||
|
||||
public void setAllowDuplicateChildName(boolean allowDuplicateChildName)
|
||||
{
|
||||
this.allowDuplicateChildName = allowDuplicateChildName;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
|
||||
|
||||
/**
|
||||
* Compiled Association Definition.
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
/*package*/ class M2ChildAssociationDefinition extends M2AssociationDefinition
|
||||
implements ChildAssociationDefinition
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct
|
||||
* @param classDef class definition
|
||||
* @param assoc child assocation
|
||||
* @param resolver namespace resolver
|
||||
*/
|
||||
/*package*/ M2ChildAssociationDefinition(ClassDefinition classDef, M2ChildAssociation assoc, NamespacePrefixResolver resolver)
|
||||
{
|
||||
super(classDef, assoc, resolver);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ChildAssociationDefinition#getRequiredChildName()
|
||||
*/
|
||||
public String getRequiredChildName()
|
||||
{
|
||||
return ((M2ChildAssociation)getM2Association()).getRequiredChildName();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ChildAssociationDefinition#getDuplicateChildNamesAllowed()
|
||||
*/
|
||||
public boolean getDuplicateChildNamesAllowed()
|
||||
{
|
||||
return ((M2ChildAssociation)getM2Association()).allowDuplicateChildName();
|
||||
}
|
||||
|
||||
}
|
233
source/java/org/alfresco/repo/dictionary/M2Class.java
Normal file
233
source/java/org/alfresco/repo/dictionary/M2Class.java
Normal file
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Abstract Class Definition.
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public abstract class M2Class
|
||||
{
|
||||
private String name = null;
|
||||
private String title = null;
|
||||
private String description = null;
|
||||
private String parentName = null;
|
||||
|
||||
private List<M2Property> properties = new ArrayList<M2Property>();
|
||||
private List<M2PropertyOverride> propertyOverrides = new ArrayList<M2PropertyOverride>();
|
||||
private List<M2ClassAssociation> associations = new ArrayList<M2ClassAssociation>();
|
||||
private List<String> mandatoryAspects = new ArrayList<String>();
|
||||
|
||||
/*package*/ M2Class()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
|
||||
public String getParentName()
|
||||
{
|
||||
return parentName;
|
||||
}
|
||||
|
||||
|
||||
public void setParentName(String parentName)
|
||||
{
|
||||
this.parentName = parentName;
|
||||
}
|
||||
|
||||
|
||||
public M2Property createProperty(String name)
|
||||
{
|
||||
M2Property property = new M2Property();
|
||||
property.setName(name);
|
||||
properties.add(property);
|
||||
return property;
|
||||
}
|
||||
|
||||
|
||||
public void removeProperty(String name)
|
||||
{
|
||||
M2Property property = getProperty(name);
|
||||
if (property != null)
|
||||
{
|
||||
properties.remove(property);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<M2Property> getProperties()
|
||||
{
|
||||
return Collections.unmodifiableList(properties);
|
||||
}
|
||||
|
||||
|
||||
public M2Property getProperty(String name)
|
||||
{
|
||||
for (M2Property candidate : properties)
|
||||
{
|
||||
if (candidate.getName().equals(name))
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public M2Association createAssociation(String name)
|
||||
{
|
||||
M2Association association = new M2Association();
|
||||
association.setName(name);
|
||||
associations.add(association);
|
||||
return association;
|
||||
}
|
||||
|
||||
|
||||
public M2ChildAssociation createChildAssociation(String name)
|
||||
{
|
||||
M2ChildAssociation association = new M2ChildAssociation();
|
||||
association.setName(name);
|
||||
associations.add(association);
|
||||
return association;
|
||||
}
|
||||
|
||||
|
||||
public void removeAssociation(String name)
|
||||
{
|
||||
M2ClassAssociation association = getAssociation(name);
|
||||
if (association != null)
|
||||
{
|
||||
associations.remove(association);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<M2ClassAssociation> getAssociations()
|
||||
{
|
||||
return Collections.unmodifiableList(associations);
|
||||
}
|
||||
|
||||
|
||||
public M2ClassAssociation getAssociation(String name)
|
||||
{
|
||||
for (M2ClassAssociation candidate : associations)
|
||||
{
|
||||
if (candidate.getName().equals(name))
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public M2PropertyOverride createPropertyOverride(String name)
|
||||
{
|
||||
M2PropertyOverride property = new M2PropertyOverride();
|
||||
property.setName(name);
|
||||
propertyOverrides.add(property);
|
||||
return property;
|
||||
}
|
||||
|
||||
|
||||
public void removePropertyOverride(String name)
|
||||
{
|
||||
M2PropertyOverride property = getPropertyOverride(name);
|
||||
if (property != null)
|
||||
{
|
||||
propertyOverrides.remove(property);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<M2PropertyOverride> getPropertyOverrides()
|
||||
{
|
||||
return Collections.unmodifiableList(propertyOverrides);
|
||||
}
|
||||
|
||||
|
||||
public M2PropertyOverride getPropertyOverride(String name)
|
||||
{
|
||||
for (M2PropertyOverride candidate : propertyOverrides)
|
||||
{
|
||||
if (candidate.getName().equals(name))
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addMandatoryAspect(String name)
|
||||
{
|
||||
mandatoryAspects.add(name);
|
||||
}
|
||||
|
||||
|
||||
public void removeMandatoryAspect(String name)
|
||||
{
|
||||
mandatoryAspects.remove(name);
|
||||
}
|
||||
|
||||
|
||||
public List<String> getMandatoryAspects()
|
||||
{
|
||||
return Collections.unmodifiableList(mandatoryAspects);
|
||||
}
|
||||
|
||||
}
|
189
source/java/org/alfresco/repo/dictionary/M2ClassAssociation.java
Normal file
189
source/java/org/alfresco/repo/dictionary/M2ClassAssociation.java
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract Association Definition.
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public abstract class M2ClassAssociation
|
||||
{
|
||||
private String name = null;
|
||||
private Boolean isProtected = null;
|
||||
private String title = null;
|
||||
private String description = null;
|
||||
private String sourceRoleName = null;
|
||||
private Boolean isSourceMandatory = null;
|
||||
private Boolean isSourceMany = null;
|
||||
private String targetClassName = null;
|
||||
private String targetRoleName = null;
|
||||
private Boolean isTargetMandatory = null;
|
||||
private Boolean isTargetMany = null;
|
||||
|
||||
|
||||
/*package*/ M2ClassAssociation()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*package*/ M2ClassAssociation(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public boolean isChild()
|
||||
{
|
||||
return this instanceof M2ChildAssociation;
|
||||
}
|
||||
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public boolean isProtected()
|
||||
{
|
||||
return isProtected == null ? false : isProtected;
|
||||
}
|
||||
|
||||
|
||||
public void setProtected(boolean isProtected)
|
||||
{
|
||||
this.isProtected = isProtected;
|
||||
}
|
||||
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
|
||||
public String getSourceRoleName()
|
||||
{
|
||||
return sourceRoleName;
|
||||
}
|
||||
|
||||
|
||||
public void setSourceRoleName(String name)
|
||||
{
|
||||
this.sourceRoleName = name;
|
||||
}
|
||||
|
||||
|
||||
public boolean isSourceMandatory()
|
||||
{
|
||||
return isSourceMandatory == null ? true : isSourceMandatory;
|
||||
}
|
||||
|
||||
|
||||
public void setSourceMandatory(boolean isSourceMandatory)
|
||||
{
|
||||
this.isSourceMandatory = isSourceMandatory;
|
||||
}
|
||||
|
||||
|
||||
public boolean isSourceMany()
|
||||
{
|
||||
return isSourceMany == null ? false : isSourceMany;
|
||||
}
|
||||
|
||||
|
||||
public void setSourceMany(boolean isSourceMany)
|
||||
{
|
||||
this.isSourceMany = isSourceMany;
|
||||
}
|
||||
|
||||
|
||||
public String getTargetClassName()
|
||||
{
|
||||
return targetClassName;
|
||||
}
|
||||
|
||||
|
||||
public void setTargetClassName(String targetClassName)
|
||||
{
|
||||
this.targetClassName = targetClassName;
|
||||
}
|
||||
|
||||
|
||||
public String getTargetRoleName()
|
||||
{
|
||||
return targetRoleName;
|
||||
}
|
||||
|
||||
|
||||
public void setTargetRoleName(String name)
|
||||
{
|
||||
this.targetRoleName = name;
|
||||
}
|
||||
|
||||
|
||||
public boolean isTargetMandatory()
|
||||
{
|
||||
return isTargetMandatory == null ? false : isTargetMandatory;
|
||||
}
|
||||
|
||||
|
||||
public void setTargetMandatory(boolean isTargetMandatory)
|
||||
{
|
||||
this.isTargetMandatory = isTargetMandatory;
|
||||
}
|
||||
|
||||
|
||||
public boolean isTargetMany()
|
||||
{
|
||||
return isTargetMany == null ? true : isTargetMany;
|
||||
}
|
||||
|
||||
|
||||
public void setTargetMany(boolean isTargetMany)
|
||||
{
|
||||
this.isTargetMany = isTargetMany;
|
||||
}
|
||||
|
||||
}
|
408
source/java/org/alfresco/repo/dictionary/M2ClassDefinition.java
Normal file
408
source/java/org/alfresco/repo/dictionary/M2ClassDefinition.java
Normal file
@@ -0,0 +1,408 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Compiled Class Definition
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
/*package*/ class M2ClassDefinition implements ClassDefinition
|
||||
{
|
||||
protected ModelDefinition model;
|
||||
protected M2Class m2Class;
|
||||
protected QName name;
|
||||
protected QName parentName = null;
|
||||
|
||||
private Map<QName, M2PropertyOverride> propertyOverrides = new HashMap<QName, M2PropertyOverride>();
|
||||
private Map<QName, PropertyDefinition> properties = new HashMap<QName, PropertyDefinition>();
|
||||
private Map<QName, PropertyDefinition> inheritedProperties = new HashMap<QName, PropertyDefinition>();
|
||||
private Map<QName, AssociationDefinition> associations = new HashMap<QName, AssociationDefinition>();
|
||||
private Map<QName, AssociationDefinition> inheritedAssociations = new HashMap<QName, AssociationDefinition>();
|
||||
private Map<QName, ChildAssociationDefinition> inheritedChildAssociations = new HashMap<QName, ChildAssociationDefinition>();
|
||||
private List<AspectDefinition> defaultAspects = new ArrayList<AspectDefinition>();
|
||||
private List<QName> defaultAspectNames = new ArrayList<QName>();
|
||||
private List<AspectDefinition> inheritedDefaultAspects = new ArrayList<AspectDefinition>();
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param m2Class class definition
|
||||
* @param resolver namepsace resolver
|
||||
* @param modelProperties global list of model properties
|
||||
* @param modelAssociations global list of model associations
|
||||
*/
|
||||
/*package*/ M2ClassDefinition(ModelDefinition model, M2Class m2Class, NamespacePrefixResolver resolver, Map<QName, PropertyDefinition> modelProperties, Map<QName, AssociationDefinition> modelAssociations)
|
||||
{
|
||||
this.model = model;
|
||||
this.m2Class = m2Class;
|
||||
|
||||
// Resolve Names
|
||||
this.name = QName.createQName(m2Class.getName(), resolver);
|
||||
if (m2Class.getParentName() != null && m2Class.getParentName().length() > 0)
|
||||
{
|
||||
this.parentName = QName.createQName(m2Class.getParentName(), resolver);
|
||||
}
|
||||
|
||||
// Construct Properties
|
||||
for (M2Property property : m2Class.getProperties())
|
||||
{
|
||||
PropertyDefinition def = new M2PropertyDefinition(this, property, resolver);
|
||||
if (properties.containsKey(def.getName()))
|
||||
{
|
||||
throw new DictionaryException("Found duplicate property definition " + def.getName().toPrefixString() + " within class " + name.toPrefixString());
|
||||
}
|
||||
|
||||
// Check for existence of property elsewhere within the model
|
||||
PropertyDefinition existingDef = modelProperties.get(def.getName());
|
||||
if (existingDef != null)
|
||||
{
|
||||
// TODO: Consider sharing property, if property definitions are equal
|
||||
throw new DictionaryException("Found duplicate property definition " + def.getName().toPrefixString() + " within class "
|
||||
+ name.toPrefixString() + " and class " + existingDef.getContainerClass().getName().toPrefixString());
|
||||
}
|
||||
|
||||
properties.put(def.getName(), def);
|
||||
modelProperties.put(def.getName(), def);
|
||||
}
|
||||
|
||||
// Construct Associations
|
||||
for (M2ClassAssociation assoc : m2Class.getAssociations())
|
||||
{
|
||||
AssociationDefinition def;
|
||||
if (assoc instanceof M2ChildAssociation)
|
||||
{
|
||||
def = new M2ChildAssociationDefinition(this, (M2ChildAssociation)assoc, resolver);
|
||||
}
|
||||
else
|
||||
{
|
||||
def = new M2AssociationDefinition(this, assoc, resolver);
|
||||
}
|
||||
if (associations.containsKey(def.getName()))
|
||||
{
|
||||
throw new DictionaryException("Found duplicate association definition " + def.getName().toPrefixString() + " within class " + name.toPrefixString());
|
||||
}
|
||||
|
||||
// Check for existence of association elsewhere within the model
|
||||
AssociationDefinition existingDef = modelAssociations.get(def.getName());
|
||||
if (existingDef != null)
|
||||
{
|
||||
// TODO: Consider sharing association, if association definitions are equal
|
||||
throw new DictionaryException("Found duplicate association definition " + def.getName().toPrefixString() + " within class "
|
||||
+ name.toPrefixString() + " and class " + existingDef.getSourceClass().getName().toPrefixString());
|
||||
}
|
||||
|
||||
associations.put(def.getName(), def);
|
||||
modelAssociations.put(def.getName(), def);
|
||||
}
|
||||
|
||||
// Construct Property overrides
|
||||
for (M2PropertyOverride override : m2Class.getPropertyOverrides())
|
||||
{
|
||||
QName overrideName = QName.createQName(override.getName(), resolver);
|
||||
if (properties.containsKey(overrideName))
|
||||
{
|
||||
throw new DictionaryException("Found duplicate property and property override definition " + overrideName.toPrefixString() + " within class " + name.toPrefixString());
|
||||
}
|
||||
if (propertyOverrides.containsKey(overrideName))
|
||||
{
|
||||
throw new DictionaryException("Found duplicate property override definition " + overrideName.toPrefixString() + " within class " + name.toPrefixString());
|
||||
}
|
||||
propertyOverrides.put(overrideName, override);
|
||||
}
|
||||
|
||||
// Resolve qualified names
|
||||
for (String aspectName : m2Class.getMandatoryAspects())
|
||||
{
|
||||
QName name = QName.createQName(aspectName, resolver);
|
||||
if (!defaultAspectNames.contains(name))
|
||||
{
|
||||
defaultAspectNames.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(120);
|
||||
sb.append("ClassDef ")
|
||||
.append("[ name=").append(name)
|
||||
.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/*package*/ void resolveDependencies(ModelQuery query)
|
||||
{
|
||||
if (parentName != null)
|
||||
{
|
||||
ClassDefinition parent = query.getClass(parentName);
|
||||
if (parent == null)
|
||||
{
|
||||
throw new DictionaryException("Parent class " + parentName.toPrefixString() + " of class " + name.toPrefixString() + " is not found");
|
||||
}
|
||||
}
|
||||
|
||||
for (PropertyDefinition def : properties.values())
|
||||
{
|
||||
((M2PropertyDefinition)def).resolveDependencies(query);
|
||||
}
|
||||
for (AssociationDefinition def : associations.values())
|
||||
{
|
||||
((M2AssociationDefinition)def).resolveDependencies(query);
|
||||
}
|
||||
|
||||
for (QName aspectName : defaultAspectNames)
|
||||
{
|
||||
AspectDefinition aspect = query.getAspect(aspectName);
|
||||
if (aspect == null)
|
||||
{
|
||||
throw new DictionaryException("Mandatory aspect " + aspectName.toPrefixString() + " of class " + name.toPrefixString() + " is not found");
|
||||
}
|
||||
defaultAspects.add(aspect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*package*/ void resolveInheritance(ModelQuery query)
|
||||
{
|
||||
// Retrieve parent class
|
||||
ClassDefinition parentClass = (parentName == null) ? null : query.getClass(parentName);
|
||||
|
||||
// Build list of inherited properties (and process overridden values)
|
||||
if (parentClass != null)
|
||||
{
|
||||
for (PropertyDefinition def : parentClass.getProperties().values())
|
||||
{
|
||||
M2PropertyOverride override = propertyOverrides.get(def.getName());
|
||||
if (override == null)
|
||||
{
|
||||
inheritedProperties.put(def.getName(), def);
|
||||
}
|
||||
else
|
||||
{
|
||||
inheritedProperties.put(def.getName(), new M2PropertyDefinition(this, def, override));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Append list of defined properties
|
||||
for (PropertyDefinition def : properties.values())
|
||||
{
|
||||
if (inheritedProperties.containsKey(def.getName()))
|
||||
{
|
||||
throw new DictionaryException("Duplicate property definition " + def.getName().toPrefixString() + " found in class hierarchy of " + name.toPrefixString());
|
||||
}
|
||||
inheritedProperties.put(def.getName(), def);
|
||||
}
|
||||
|
||||
// Build list of inherited associations
|
||||
if (parentClass != null)
|
||||
{
|
||||
inheritedAssociations.putAll(parentClass.getAssociations());
|
||||
}
|
||||
|
||||
// Append list of defined associations
|
||||
for (AssociationDefinition def : associations.values())
|
||||
{
|
||||
if (inheritedAssociations.containsKey(def.getName()))
|
||||
{
|
||||
throw new DictionaryException("Duplicate association definition " + def.getName().toPrefixString() + " found in class hierarchy of " + name.toPrefixString());
|
||||
}
|
||||
inheritedAssociations.put(def.getName(), def);
|
||||
}
|
||||
|
||||
// Derive Child Associations
|
||||
for (AssociationDefinition def : inheritedAssociations.values())
|
||||
{
|
||||
if (def instanceof ChildAssociationDefinition)
|
||||
{
|
||||
inheritedChildAssociations.put(def.getName(), (ChildAssociationDefinition)def);
|
||||
}
|
||||
}
|
||||
|
||||
// Build list of inherited default aspects
|
||||
if (parentClass != null)
|
||||
{
|
||||
inheritedDefaultAspects.addAll(parentClass.getDefaultAspects());
|
||||
}
|
||||
|
||||
// Append list of defined default aspects
|
||||
for (AspectDefinition def : defaultAspects)
|
||||
{
|
||||
if (!inheritedDefaultAspects.contains(def))
|
||||
{
|
||||
inheritedDefaultAspects.add(def);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.dictionary.ClassDefinition#getModel()
|
||||
*/
|
||||
public ModelDefinition getModel()
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#getName()
|
||||
*/
|
||||
public QName getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#getTitle()
|
||||
*/
|
||||
public String getTitle()
|
||||
{
|
||||
String value = M2Label.getLabel(model, "class", name, "title");
|
||||
if (value == null)
|
||||
{
|
||||
value = m2Class.getTitle();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#getDescription()
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
String value = M2Label.getLabel(model, "class", name, "description");
|
||||
if (value == null)
|
||||
{
|
||||
value = m2Class.getDescription();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#isAspect()
|
||||
*/
|
||||
public boolean isAspect()
|
||||
{
|
||||
return (m2Class instanceof M2Aspect);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#getParentName()
|
||||
*/
|
||||
public QName getParentName()
|
||||
{
|
||||
return parentName;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#getProperties()
|
||||
*/
|
||||
public Map<QName, PropertyDefinition> getProperties()
|
||||
{
|
||||
return Collections.unmodifiableMap(inheritedProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.dictionary.ClassDefinition#getDefaultValues()
|
||||
*/
|
||||
public Map<QName, Serializable> getDefaultValues()
|
||||
{
|
||||
Map<QName, Serializable> result = new HashMap<QName, Serializable>(5);
|
||||
|
||||
for(Map.Entry<QName, PropertyDefinition> entry : inheritedProperties.entrySet())
|
||||
{
|
||||
PropertyDefinition propertyDefinition = entry.getValue();
|
||||
String defaultValue = propertyDefinition.getDefaultValue();
|
||||
if (defaultValue != null)
|
||||
{
|
||||
result.put(entry.getKey(), defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.unmodifiableMap(result);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#getAssociations()
|
||||
*/
|
||||
public Map<QName, AssociationDefinition> getAssociations()
|
||||
{
|
||||
return Collections.unmodifiableMap(inheritedAssociations);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.dictionary.ClassDefinition#getDefaultAspects()
|
||||
*/
|
||||
public List<AspectDefinition> getDefaultAspects()
|
||||
{
|
||||
return inheritedDefaultAspects;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.dictionary.ClassDefinition#isContainer()
|
||||
*/
|
||||
public boolean isContainer()
|
||||
{
|
||||
return !inheritedChildAssociations.isEmpty();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ClassDefinition#getChildAssociations()
|
||||
*/
|
||||
public Map<QName, ChildAssociationDefinition> getChildAssociations()
|
||||
{
|
||||
return Collections.unmodifiableMap(inheritedChildAssociations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (!(obj instanceof M2ClassDefinition))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return name.equals(((M2ClassDefinition)obj).name);
|
||||
}
|
||||
|
||||
}
|
100
source/java/org/alfresco/repo/dictionary/M2DataType.java
Normal file
100
source/java/org/alfresco/repo/dictionary/M2DataType.java
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
|
||||
/**
|
||||
* Property Type Definition
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public class M2DataType
|
||||
{
|
||||
private String name = null;
|
||||
private String title = null;
|
||||
private String description = null;
|
||||
private String analyserClassName = null;
|
||||
private String javaClassName = null;
|
||||
|
||||
|
||||
/*package*/ M2DataType()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
|
||||
public String getAnalyserClassName()
|
||||
{
|
||||
return analyserClassName;
|
||||
}
|
||||
|
||||
|
||||
public void setAnalyserClassName(String analyserClassName)
|
||||
{
|
||||
this.analyserClassName = analyserClassName;;
|
||||
}
|
||||
|
||||
|
||||
public String getJavaClassName()
|
||||
{
|
||||
return javaClassName;
|
||||
}
|
||||
|
||||
|
||||
public void setJavaClassName(String javaClassName)
|
||||
{
|
||||
this.javaClassName = javaClassName;;
|
||||
}
|
||||
|
||||
}
|
@@ -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.repo.dictionary;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Compiled Property Type Definition
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
/*package*/ class M2DataTypeDefinition implements DataTypeDefinition
|
||||
{
|
||||
private ModelDefinition model;
|
||||
private QName name;
|
||||
private M2DataType dataType;
|
||||
|
||||
|
||||
/*package*/ M2DataTypeDefinition(ModelDefinition model, M2DataType propertyType, NamespacePrefixResolver resolver)
|
||||
{
|
||||
this.model = model;
|
||||
this.name = QName.createQName(propertyType.getName(), resolver);
|
||||
this.dataType = propertyType;
|
||||
}
|
||||
|
||||
|
||||
/*package*/ void resolveDependencies(ModelQuery query)
|
||||
{
|
||||
// Ensure java class has been specified
|
||||
String javaClass = dataType.getJavaClassName();
|
||||
if (javaClass == null)
|
||||
{
|
||||
throw new DictionaryException("Java class of data type " + name.toPrefixString() + " must be specified");
|
||||
}
|
||||
|
||||
// Ensure java class is valid and referenceable
|
||||
try
|
||||
{
|
||||
Class.forName(javaClass);
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
throw new DictionaryException("Java class " + javaClass + " of data type " + name.toPrefixString() + " is invalid", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #getName()
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return getName().toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.dictionary.DataTypeDefinition#getModel()
|
||||
*/
|
||||
public ModelDefinition getModel()
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyTypeDefinition#getName()
|
||||
*/
|
||||
public QName getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyTypeDefinition#getTitle()
|
||||
*/
|
||||
public String getTitle()
|
||||
{
|
||||
String value = M2Label.getLabel(model, "datatype", name, "title");
|
||||
if (value == null)
|
||||
{
|
||||
value = dataType.getTitle();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyTypeDefinition#getDescription()
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
String value = M2Label.getLabel(model, "datatype", name, "description");
|
||||
if (value == null)
|
||||
{
|
||||
value = dataType.getDescription();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyTypeDefinition#getAnalyserClassName()
|
||||
*/
|
||||
public String getAnalyserClassName()
|
||||
{
|
||||
return getAnalyserClassName(I18NUtil.getLocale());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.dictionary.DataTypeDefinition#getAnalyserClassName(java.util.Locale)
|
||||
*/
|
||||
public String getAnalyserClassName(Locale locale)
|
||||
{
|
||||
String value = M2Label.getLabel(locale, model, "datatype", name, "analyzer");
|
||||
if (value == null)
|
||||
{
|
||||
value = dataType.getAnalyserClassName();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.dictionary.PropertyTypeDefinition#getJavaClassName()
|
||||
*/
|
||||
public String getJavaClassName()
|
||||
{
|
||||
return dataType.getJavaClassName();
|
||||
}
|
||||
|
||||
}
|
75
source/java/org/alfresco/repo/dictionary/M2Label.java
Normal file
75
source/java/org/alfresco/repo/dictionary/M2Label.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Helper for obtaining display labels for data dictionary items
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class M2Label
|
||||
{
|
||||
|
||||
/**
|
||||
* Get label for data dictionary item given specified locale
|
||||
*
|
||||
* @param locale
|
||||
* @param model
|
||||
* @param type
|
||||
* @param item
|
||||
* @param label
|
||||
* @return
|
||||
*/
|
||||
public static String getLabel(Locale locale, ModelDefinition model, String type, QName item, String label)
|
||||
{
|
||||
String key = model.getName().toPrefixString();
|
||||
if (type != null)
|
||||
{
|
||||
key += "." + type;
|
||||
}
|
||||
if (item != null)
|
||||
{
|
||||
key += "." + item.toPrefixString();
|
||||
}
|
||||
key += "." + label;
|
||||
key = StringUtils.replace(key, ":", "_");
|
||||
return I18NUtil.getMessage(key, locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get label for data dictionary item
|
||||
*
|
||||
* @param model
|
||||
* @param type
|
||||
* @param item
|
||||
* @param label
|
||||
* @return
|
||||
*/
|
||||
public static String getLabel(ModelDefinition model, String type, QName item, String label)
|
||||
{
|
||||
return getLabel(I18NUtil.getLocale(), model, type, item, label);
|
||||
}
|
||||
|
||||
}
|
389
source/java/org/alfresco/repo/dictionary/M2Model.java
Normal file
389
source/java/org/alfresco/repo/dictionary/M2Model.java
Normal file
@@ -0,0 +1,389 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||
import org.jibx.runtime.BindingDirectory;
|
||||
import org.jibx.runtime.IBindingFactory;
|
||||
import org.jibx.runtime.IMarshallingContext;
|
||||
import org.jibx.runtime.IUnmarshallingContext;
|
||||
import org.jibx.runtime.JiBXException;
|
||||
|
||||
|
||||
/**
|
||||
* Model Definition.
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public class M2Model
|
||||
{
|
||||
private String name = null;
|
||||
private String description = null;
|
||||
private String author = null;
|
||||
private Date published = null;
|
||||
private String version;
|
||||
|
||||
private List<M2Namespace> namespaces = new ArrayList<M2Namespace>();
|
||||
private List<M2Namespace> imports = new ArrayList<M2Namespace>();
|
||||
private List<M2DataType> dataTypes = new ArrayList<M2DataType>();
|
||||
private List<M2Type> types = new ArrayList<M2Type>();
|
||||
private List<M2Aspect> aspects = new ArrayList<M2Aspect>();
|
||||
|
||||
|
||||
private M2Model()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct an empty model
|
||||
*
|
||||
* @param name the name of the model
|
||||
* @return the model
|
||||
*/
|
||||
public static M2Model createModel(String name)
|
||||
{
|
||||
M2Model model = new M2Model();
|
||||
model.name = name;
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct a model from a dictionary xml specification
|
||||
*
|
||||
* @param xml the dictionary xml
|
||||
* @return the model representation of the xml
|
||||
*/
|
||||
public static M2Model createModel(InputStream xml)
|
||||
{
|
||||
try
|
||||
{
|
||||
IBindingFactory factory = BindingDirectory.getFactory(M2Model.class);
|
||||
IUnmarshallingContext context = factory.createUnmarshallingContext();
|
||||
Object obj = context.unmarshalDocument(xml, null);
|
||||
return (M2Model)obj;
|
||||
}
|
||||
catch(JiBXException e)
|
||||
{
|
||||
throw new DictionaryException("Failed to parse model", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the model to dictionary XML
|
||||
*
|
||||
* @param xml the dictionary xml representation of the model
|
||||
*/
|
||||
public void toXML(OutputStream xml)
|
||||
{
|
||||
try
|
||||
{
|
||||
IBindingFactory factory = BindingDirectory.getFactory(M2Model.class);
|
||||
IMarshallingContext context = factory.createMarshallingContext();
|
||||
context.setIndent(4);
|
||||
context.marshalDocument(this, "UTF-8", null, xml);
|
||||
}
|
||||
catch(JiBXException e)
|
||||
{
|
||||
throw new DictionaryException("Failed to create M2 Model", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a compiled form of this model
|
||||
*
|
||||
* @param dictionaryDAO dictionary DAO
|
||||
* @param namespaceDAO namespace DAO
|
||||
* @return the compiled form of the model
|
||||
*/
|
||||
/*package*/ CompiledModel compile(DictionaryDAO dictionaryDAO, NamespaceDAO namespaceDAO)
|
||||
{
|
||||
CompiledModel compiledModel = new CompiledModel(this, dictionaryDAO, namespaceDAO);
|
||||
return compiledModel;
|
||||
}
|
||||
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
|
||||
public String getAuthor()
|
||||
{
|
||||
return author;
|
||||
}
|
||||
|
||||
|
||||
public void setAuthor(String author)
|
||||
{
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
|
||||
public Date getPublishedDate()
|
||||
{
|
||||
return published;
|
||||
}
|
||||
|
||||
|
||||
public void setPublishedDate(Date published)
|
||||
{
|
||||
this.published = published;
|
||||
}
|
||||
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
public void setVersion(String version)
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
|
||||
public M2Type createType(String name)
|
||||
{
|
||||
M2Type type = new M2Type();
|
||||
type.setName(name);
|
||||
types.add(type);
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
public void removeType(String name)
|
||||
{
|
||||
M2Type type = getType(name);
|
||||
if (type != null)
|
||||
{
|
||||
types.remove(types);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<M2Type> getTypes()
|
||||
{
|
||||
return Collections.unmodifiableList(types);
|
||||
}
|
||||
|
||||
|
||||
public M2Type getType(String name)
|
||||
{
|
||||
for (M2Type candidate : types)
|
||||
{
|
||||
if (candidate.getName().equals(name))
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public M2Aspect createAspect(String name)
|
||||
{
|
||||
M2Aspect aspect = new M2Aspect();
|
||||
aspect.setName(name);
|
||||
aspects.add(aspect);
|
||||
return aspect;
|
||||
}
|
||||
|
||||
|
||||
public void removeAspect(String name)
|
||||
{
|
||||
M2Aspect aspect = getAspect(name);
|
||||
if (aspect != null)
|
||||
{
|
||||
aspects.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<M2Aspect> getAspects()
|
||||
{
|
||||
return Collections.unmodifiableList(aspects);
|
||||
}
|
||||
|
||||
|
||||
public M2Aspect getAspect(String name)
|
||||
{
|
||||
for (M2Aspect candidate : aspects)
|
||||
{
|
||||
if (candidate.getName().equals(name))
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public M2DataType createPropertyType(String name)
|
||||
{
|
||||
M2DataType type = new M2DataType();
|
||||
type .setName(name);
|
||||
dataTypes.add(type);
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
public void removePropertyType(String name)
|
||||
{
|
||||
M2DataType type = getPropertyType(name);
|
||||
if (type != null)
|
||||
{
|
||||
dataTypes.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<M2DataType> getPropertyTypes()
|
||||
{
|
||||
return Collections.unmodifiableList(dataTypes);
|
||||
}
|
||||
|
||||
|
||||
public M2DataType getPropertyType(String name)
|
||||
{
|
||||
for (M2DataType candidate : dataTypes)
|
||||
{
|
||||
if (candidate.getName().equals(name))
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public M2Namespace createNamespace(String uri, String prefix)
|
||||
{
|
||||
M2Namespace namespace = new M2Namespace();
|
||||
namespace.setUri(uri);
|
||||
namespace.setPrefix(prefix);
|
||||
namespaces.add(namespace);
|
||||
return namespace;
|
||||
}
|
||||
|
||||
|
||||
public void removeNamespace(String uri)
|
||||
{
|
||||
M2Namespace namespace = getNamespace(uri);
|
||||
if (namespace != null)
|
||||
{
|
||||
namespaces.remove(namespace);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<M2Namespace> getNamespaces()
|
||||
{
|
||||
return Collections.unmodifiableList(namespaces);
|
||||
}
|
||||
|
||||
|
||||
public M2Namespace getNamespace(String uri)
|
||||
{
|
||||
for (M2Namespace candidate : namespaces)
|
||||
{
|
||||
if (candidate.getUri().equals(uri))
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public M2Namespace createImport(String uri, String prefix)
|
||||
{
|
||||
M2Namespace namespace = new M2Namespace();
|
||||
namespace.setUri(uri);
|
||||
namespace.setPrefix(prefix);
|
||||
imports.add(namespace);
|
||||
return namespace;
|
||||
}
|
||||
|
||||
|
||||
public void removeImport(String uri)
|
||||
{
|
||||
M2Namespace namespace = getImport(uri);
|
||||
if (namespace != null)
|
||||
{
|
||||
imports.remove(namespace);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<M2Namespace> getImports()
|
||||
{
|
||||
return Collections.unmodifiableList(imports);
|
||||
}
|
||||
|
||||
|
||||
public M2Namespace getImport(String uri)
|
||||
{
|
||||
for (M2Namespace candidate : imports)
|
||||
{
|
||||
if (candidate.getUri().equals(uri))
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// Do not delete: referenced by m2binding.xml
|
||||
private static List createList()
|
||||
{
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Compiled Model Definition
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public class M2ModelDefinition implements ModelDefinition
|
||||
{
|
||||
private QName name;
|
||||
private M2Model model;
|
||||
|
||||
|
||||
/*package*/ M2ModelDefinition(M2Model model, NamespacePrefixResolver resolver)
|
||||
{
|
||||
this.name = QName.createQName(model.getName(), resolver);
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ModelDefinition#getName()
|
||||
*/
|
||||
public QName getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ModelDefinition#getDescription()
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
String value = M2Label.getLabel(this, null, null, "description");
|
||||
if (value == null)
|
||||
{
|
||||
value = model.getDescription();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ModelDefinition#getAuthor()
|
||||
*/
|
||||
public String getAuthor()
|
||||
{
|
||||
return model.getAuthor();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ModelDefinition#getPublishedDate()
|
||||
*/
|
||||
public Date getPublishedDate()
|
||||
{
|
||||
return model.getPublishedDate();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.ModelDefinition#getVersion()
|
||||
*/
|
||||
public String getVersion()
|
||||
{
|
||||
return model.getVersion();
|
||||
}
|
||||
|
||||
}
|
60
source/java/org/alfresco/repo/dictionary/M2Namespace.java
Normal file
60
source/java/org/alfresco/repo/dictionary/M2Namespace.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
|
||||
/**
|
||||
* Namespace Definition.
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public class M2Namespace
|
||||
{
|
||||
private String uri = null;
|
||||
private String prefix = null;
|
||||
|
||||
|
||||
/*package*/ M2Namespace()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public String getUri()
|
||||
{
|
||||
return uri;
|
||||
}
|
||||
|
||||
|
||||
public void setUri(String uri)
|
||||
{
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
|
||||
public String getPrefix()
|
||||
{
|
||||
return prefix;
|
||||
}
|
||||
|
||||
|
||||
public void setPrefix(String prefix)
|
||||
{
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
}
|
196
source/java/org/alfresco/repo/dictionary/M2Property.java
Normal file
196
source/java/org/alfresco/repo/dictionary/M2Property.java
Normal file
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
|
||||
/**
|
||||
* Property Definition
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public class M2Property
|
||||
{
|
||||
private String name = null;
|
||||
private String title = null;
|
||||
private String description = null;
|
||||
private String propertyType = null;
|
||||
private boolean isProtected = false;
|
||||
private boolean isMandatory = false;
|
||||
private boolean isMultiValued = false;
|
||||
private String defaultValue = null;
|
||||
private boolean isIndexed = true;
|
||||
private boolean isIndexedAtomically = true;
|
||||
private boolean isStoredInIndex = false;
|
||||
private boolean isTokenisedInIndex = true;
|
||||
|
||||
|
||||
/*package*/ M2Property()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*package*/ M2Property(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return propertyType;
|
||||
}
|
||||
|
||||
|
||||
public void setType(String type)
|
||||
{
|
||||
this.propertyType = type;
|
||||
}
|
||||
|
||||
|
||||
public boolean isProtected()
|
||||
{
|
||||
return isProtected;
|
||||
}
|
||||
|
||||
|
||||
public void setProtected(boolean isProtected)
|
||||
{
|
||||
this.isProtected = isProtected;
|
||||
}
|
||||
|
||||
|
||||
public boolean isMandatory()
|
||||
{
|
||||
return isMandatory;
|
||||
}
|
||||
|
||||
|
||||
public void setMandatory(boolean isMandatory)
|
||||
{
|
||||
this.isMandatory = isMandatory;
|
||||
}
|
||||
|
||||
|
||||
public boolean isMultiValued()
|
||||
{
|
||||
return isMultiValued;
|
||||
}
|
||||
|
||||
|
||||
public void setMultiValued(boolean isMultiValued)
|
||||
{
|
||||
this.isMultiValued = isMultiValued;
|
||||
}
|
||||
|
||||
|
||||
public String getDefaultValue()
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
public void setDefaultValue(String defaultValue)
|
||||
{
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
|
||||
public boolean isIndexed()
|
||||
{
|
||||
return isIndexed;
|
||||
}
|
||||
|
||||
|
||||
public void setIndexed(boolean isIndexed)
|
||||
{
|
||||
this.isIndexed = isIndexed;
|
||||
}
|
||||
|
||||
|
||||
public boolean isStoredInIndex()
|
||||
{
|
||||
return isStoredInIndex;
|
||||
}
|
||||
|
||||
|
||||
public void setStoredInIndex(boolean isStoredInIndex)
|
||||
{
|
||||
this.isStoredInIndex = isStoredInIndex;
|
||||
}
|
||||
|
||||
|
||||
public boolean isIndexedAtomically()
|
||||
{
|
||||
return isIndexedAtomically;
|
||||
}
|
||||
|
||||
|
||||
public void setIndexedAtomically(boolean isIndexedAtomically)
|
||||
{
|
||||
this.isIndexedAtomically = isIndexedAtomically;
|
||||
}
|
||||
|
||||
|
||||
public boolean isTokenisedInIndex()
|
||||
{
|
||||
return isTokenisedInIndex;
|
||||
}
|
||||
|
||||
|
||||
public void setTokenisedInIndex(boolean isTokenisedInIndex)
|
||||
{
|
||||
this.isTokenisedInIndex = isTokenisedInIndex;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,265 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Compiled Property Definition
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
/*package*/ class M2PropertyDefinition implements PropertyDefinition
|
||||
{
|
||||
private ClassDefinition classDef;
|
||||
private M2Property property;
|
||||
private QName name;
|
||||
private QName propertyTypeName;
|
||||
private DataTypeDefinition dataType;
|
||||
|
||||
|
||||
/*package*/ M2PropertyDefinition(ClassDefinition classDef, M2Property m2Property, NamespacePrefixResolver resolver)
|
||||
{
|
||||
this.classDef = classDef;
|
||||
this.property = m2Property;
|
||||
|
||||
// Resolve Names
|
||||
this.name = QName.createQName(property.getName(), resolver);
|
||||
this.propertyTypeName = QName.createQName(property.getType(), resolver);
|
||||
}
|
||||
|
||||
|
||||
/*package*/ M2PropertyDefinition(ClassDefinition classDef, PropertyDefinition propertyDef, M2PropertyOverride override)
|
||||
{
|
||||
this.classDef = classDef;
|
||||
this.property = createOverriddenProperty(propertyDef, override);
|
||||
this.name = propertyDef.getName();
|
||||
this.dataType = propertyDef.getDataType();
|
||||
this.propertyTypeName = this.dataType.getName();
|
||||
}
|
||||
|
||||
|
||||
/*package*/ void resolveDependencies(ModelQuery query)
|
||||
{
|
||||
if (propertyTypeName == null)
|
||||
{
|
||||
throw new DictionaryException("Property type of property " + name.toPrefixString() + " must be specified");
|
||||
}
|
||||
dataType = query.getDataType(propertyTypeName);
|
||||
if (dataType == null)
|
||||
{
|
||||
throw new DictionaryException("Property type " + propertyTypeName.toPrefixString() + " of property " + name.toPrefixString() + " is not found");
|
||||
}
|
||||
|
||||
// ensure content properties are not multi-valued
|
||||
if (propertyTypeName.equals(DataTypeDefinition.CONTENT) && isMultiValued())
|
||||
{
|
||||
throw new DictionaryException("Content properties must be single-valued");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a property definition whose values are overridden
|
||||
*
|
||||
* @param propertyDef the property definition to override
|
||||
* @param override the overridden values
|
||||
* @return the property definition
|
||||
*/
|
||||
private M2Property createOverriddenProperty(PropertyDefinition propertyDef, M2PropertyOverride override)
|
||||
{
|
||||
M2Property property = new M2Property();
|
||||
|
||||
// Process Default Value
|
||||
String defaultValue = override.getDefaultValue();
|
||||
property.setDefaultValue(defaultValue == null ? propertyDef.getDefaultValue() : defaultValue);
|
||||
|
||||
// Process Mandatory Value
|
||||
Boolean isMandatory = override.isMandatory();
|
||||
if (isMandatory != null)
|
||||
{
|
||||
if (propertyDef.isMandatory() == true && isMandatory == false)
|
||||
{
|
||||
throw new DictionaryException("Cannot relax mandatory attribute of property " + propertyDef.getName().toPrefixString());
|
||||
}
|
||||
}
|
||||
property.setMandatory(isMandatory == null ? propertyDef.isMandatory() : isMandatory);
|
||||
|
||||
// Copy all other properties as they are
|
||||
property.setDescription(propertyDef.getDescription());
|
||||
property.setIndexed(propertyDef.isIndexed());
|
||||
property.setIndexedAtomically(propertyDef.isIndexedAtomically());
|
||||
property.setMultiValued(propertyDef.isMultiValued());
|
||||
property.setProtected(propertyDef.isProtected());
|
||||
property.setStoredInIndex(propertyDef.isStoredInIndex());
|
||||
property.setTitle(propertyDef.getTitle());
|
||||
property.setTokenisedInIndex(propertyDef.isTokenisedInIndex());
|
||||
|
||||
return property;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #getName()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getName().toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.dictionary.PropertyDefinition#getModel()
|
||||
*/
|
||||
public ModelDefinition getModel()
|
||||
{
|
||||
return classDef.getModel();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyDefinition#getName()
|
||||
*/
|
||||
public QName getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyDefinition#getTitle()
|
||||
*/
|
||||
public String getTitle()
|
||||
{
|
||||
String value = M2Label.getLabel(classDef.getModel(), "property", name, "title");
|
||||
if (value == null)
|
||||
{
|
||||
value = property.getTitle();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyDefinition#getDescription()
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
String value = M2Label.getLabel(classDef.getModel(), "property", name, "description");
|
||||
if (value == null)
|
||||
{
|
||||
value = property.getDescription();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyDefinition#getDefaultValue()
|
||||
*/
|
||||
public String getDefaultValue()
|
||||
{
|
||||
return property.getDefaultValue();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyDefinition#getPropertyType()
|
||||
*/
|
||||
public DataTypeDefinition getDataType()
|
||||
{
|
||||
return dataType;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyDefinition#getContainerClass()
|
||||
*/
|
||||
public ClassDefinition getContainerClass()
|
||||
{
|
||||
return classDef;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyDefinition#isMultiValued()
|
||||
*/
|
||||
public boolean isMultiValued()
|
||||
{
|
||||
return property.isMultiValued();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyDefinition#isMandatory()
|
||||
*/
|
||||
public boolean isMandatory()
|
||||
{
|
||||
return property.isMandatory();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyDefinition#isProtected()
|
||||
*/
|
||||
public boolean isProtected()
|
||||
{
|
||||
return property.isProtected();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyDefinition#isIndexed()
|
||||
*/
|
||||
public boolean isIndexed()
|
||||
{
|
||||
return property.isIndexed();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyDefinition#isStoredInIndex()
|
||||
*/
|
||||
public boolean isStoredInIndex()
|
||||
{
|
||||
return property.isStoredInIndex();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyDefinition#isIndexedAtomically()
|
||||
*/
|
||||
public boolean isIndexedAtomically()
|
||||
{
|
||||
return property.isIndexedAtomically();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.PropertyDefinition#isTokenisedInIndex()
|
||||
*/
|
||||
public boolean isTokenisedInIndex()
|
||||
{
|
||||
return property.isTokenisedInIndex();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
|
||||
/**
|
||||
* Property override definition
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public class M2PropertyOverride
|
||||
{
|
||||
private String name;
|
||||
private Boolean isMandatory;
|
||||
private String defaultValue;
|
||||
|
||||
|
||||
/*package*/ M2PropertyOverride()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public Boolean isMandatory()
|
||||
{
|
||||
return isMandatory;
|
||||
}
|
||||
|
||||
|
||||
public void setMandatory(Boolean isMandatory)
|
||||
{
|
||||
this.isMandatory = isMandatory;
|
||||
}
|
||||
|
||||
|
||||
public String getDefaultValue()
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
public void setDefaultValue(String defaultValue)
|
||||
{
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
}
|
32
source/java/org/alfresco/repo/dictionary/M2Type.java
Normal file
32
source/java/org/alfresco/repo/dictionary/M2Type.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
|
||||
/**
|
||||
* Type Definition
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public class M2Type extends M2Class
|
||||
{
|
||||
/*package*/ M2Type()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Compiled Type Definition
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
/*package*/ class M2TypeDefinition extends M2ClassDefinition
|
||||
implements TypeDefinition
|
||||
{
|
||||
/*package*/ M2TypeDefinition(ModelDefinition model, M2Type m2Type, NamespacePrefixResolver resolver, Map<QName, PropertyDefinition> modelProperties, Map<QName, AssociationDefinition> modelAssociations)
|
||||
{
|
||||
super(model, m2Type, resolver, modelProperties, modelAssociations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription()
|
||||
{
|
||||
String value = M2Label.getLabel(model, "type", name, "description");
|
||||
|
||||
// if we don't have a description call the super class
|
||||
if (value == null)
|
||||
{
|
||||
value = super.getDescription();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle()
|
||||
{
|
||||
String value = M2Label.getLabel(model, "type", name, "title");
|
||||
|
||||
// if we don't have a title call the super class
|
||||
if (value == null)
|
||||
{
|
||||
value = super.getTitle();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
72
source/java/org/alfresco/repo/dictionary/M2XML.java
Normal file
72
source/java/org/alfresco/repo/dictionary/M2XML.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.util.CachingDateFormat;
|
||||
|
||||
|
||||
/**
|
||||
* Support translating model from and to XML
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public class M2XML
|
||||
{
|
||||
|
||||
/**
|
||||
* Convert XML date (of the form yyyy-MM-dd) to Date
|
||||
*
|
||||
* @param date the xml representation of the date
|
||||
* @return the date
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static Date deserialiseDate(String date)
|
||||
throws ParseException
|
||||
{
|
||||
Date xmlDate = null;
|
||||
if (date != null)
|
||||
{
|
||||
SimpleDateFormat df = CachingDateFormat.getDateOnlyFormat();
|
||||
xmlDate = df.parse(date);
|
||||
}
|
||||
return xmlDate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert date to XML date (of the form yyyy-MM-dd)
|
||||
*
|
||||
* @param date the date
|
||||
* @return the xml representation of the date
|
||||
*/
|
||||
public static String serialiseDate(Date date)
|
||||
{
|
||||
String xmlDate = null;
|
||||
if (date != null)
|
||||
{
|
||||
SimpleDateFormat df = CachingDateFormat.getDateOnlyFormat();
|
||||
xmlDate = df.format(date);
|
||||
}
|
||||
return xmlDate;
|
||||
}
|
||||
|
||||
}
|
92
source/java/org/alfresco/repo/dictionary/ModelQuery.java
Normal file
92
source/java/org/alfresco/repo/dictionary/ModelQuery.java
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Access to model items.
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
/*package*/ interface ModelQuery
|
||||
{
|
||||
/**
|
||||
* Gets the specified data type
|
||||
*
|
||||
* @param name name of the data type
|
||||
* @return data type definition
|
||||
*/
|
||||
public DataTypeDefinition getDataType(QName name);
|
||||
|
||||
/**
|
||||
* Gets the data type for the specified Java Class
|
||||
*
|
||||
* @param javaClass the java class
|
||||
* @return the data type definition (or null, if mapping is not available)
|
||||
*/
|
||||
public DataTypeDefinition getDataType(Class javaClass);
|
||||
|
||||
/**
|
||||
* Gets the specified type
|
||||
*
|
||||
* @param name name of the type
|
||||
* @return type definition
|
||||
*/
|
||||
public TypeDefinition getType(QName name);
|
||||
|
||||
/**
|
||||
* Gets the specified aspect
|
||||
*
|
||||
* @param name name of the aspect
|
||||
* @return aspect definition
|
||||
*/
|
||||
public AspectDefinition getAspect(QName name);
|
||||
|
||||
/**
|
||||
* Gets the specified class
|
||||
*
|
||||
* @param name name of the class
|
||||
* @return class definition
|
||||
*/
|
||||
public ClassDefinition getClass(QName name);
|
||||
|
||||
/**
|
||||
* Gets the specified property
|
||||
*
|
||||
* @param name name of the property
|
||||
* @return property definition
|
||||
*/
|
||||
public PropertyDefinition getProperty(QName name);
|
||||
|
||||
/**
|
||||
* Gets the specified association
|
||||
*
|
||||
* @param name name of the association
|
||||
* @return association definition
|
||||
*/
|
||||
public AssociationDefinition getAssociation(QName name);
|
||||
|
||||
}
|
61
source/java/org/alfresco/repo/dictionary/NamespaceDAO.java
Normal file
61
source/java/org/alfresco/repo/dictionary/NamespaceDAO.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
|
||||
|
||||
/**
|
||||
* Namespace DAO Interface.
|
||||
*
|
||||
* This DAO is responsible for retrieving and creating Namespace definitions.
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public interface NamespaceDAO extends NamespacePrefixResolver
|
||||
{
|
||||
|
||||
/**
|
||||
* Add a namespace URI
|
||||
*
|
||||
* @param uri the namespace uri to add
|
||||
*/
|
||||
public void addURI(String uri);
|
||||
|
||||
/**
|
||||
* Remove the specified URI
|
||||
*
|
||||
* @param uri the uri to remove
|
||||
*/
|
||||
public void removeURI(String uri);
|
||||
|
||||
/**
|
||||
* Add a namespace prefix
|
||||
*
|
||||
* @param prefix the prefix
|
||||
* @param uri the uri to prefix
|
||||
*/
|
||||
public void addPrefix(String prefix, String uri);
|
||||
|
||||
/**
|
||||
* Remove a namspace prefix
|
||||
*
|
||||
* @param prefix the prefix to remove
|
||||
*/
|
||||
public void removePrefix(String prefix);
|
||||
|
||||
}
|
124
source/java/org/alfresco/repo/dictionary/NamespaceDAOImpl.java
Normal file
124
source/java/org/alfresco/repo/dictionary/NamespaceDAOImpl.java
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.namespace.NamespaceException;
|
||||
|
||||
/**
|
||||
* Simple in-memory namespace DAO
|
||||
*
|
||||
* TODO: Remove the many to one mapping of prefixes to URIs
|
||||
*/
|
||||
public class NamespaceDAOImpl implements NamespaceDAO
|
||||
{
|
||||
|
||||
private List<String> uris = new ArrayList<String>();
|
||||
private HashMap<String, String> prefixes = new HashMap<String, String>();
|
||||
|
||||
|
||||
public Collection<String> getURIs()
|
||||
{
|
||||
return Collections.unmodifiableCollection(uris);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.ref.NamespacePrefixResolver#getPrefixes()
|
||||
*/
|
||||
public Collection<String> getPrefixes()
|
||||
{
|
||||
return Collections.unmodifiableCollection(prefixes.keySet());
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.NamespaceDAO#addURI(java.lang.String)
|
||||
*/
|
||||
public void addURI(String uri)
|
||||
{
|
||||
if (uris.contains(uri))
|
||||
{
|
||||
throw new NamespaceException("URI " + uri + " has already been defined");
|
||||
}
|
||||
uris.add(uri);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.NamespaceDAO#addPrefix(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void addPrefix(String prefix, String uri)
|
||||
{
|
||||
if (!uris.contains(uri))
|
||||
{
|
||||
throw new NamespaceException("Namespace URI " + uri + " does not exist");
|
||||
}
|
||||
prefixes.put(prefix, uri);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.NamespaceDAO#removeURI(java.lang.String)
|
||||
*/
|
||||
public void removeURI(String uri)
|
||||
{
|
||||
uris.remove(uri);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.impl.NamespaceDAO#removePrefix(java.lang.String)
|
||||
*/
|
||||
public void removePrefix(String prefix)
|
||||
{
|
||||
prefixes.remove(prefix);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.ref.NamespacePrefixResolver#getNamespaceURI(java.lang.String)
|
||||
*/
|
||||
public String getNamespaceURI(String prefix)
|
||||
{
|
||||
return prefixes.get(prefix);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.ref.NamespacePrefixResolver#getPrefixes(java.lang.String)
|
||||
*/
|
||||
public Collection<String> getPrefixes(String URI)
|
||||
{
|
||||
Collection<String> uriPrefixes = new ArrayList<String>();
|
||||
for (String key : prefixes.keySet())
|
||||
{
|
||||
String uri = prefixes.get(key);
|
||||
if ((uri != null) && (uri.equals(URI)))
|
||||
{
|
||||
uriPrefixes.add(key);
|
||||
}
|
||||
}
|
||||
return uriPrefixes;
|
||||
}
|
||||
|
||||
}
|
82
source/java/org/alfresco/repo/dictionary/TestModel.java
Normal file
82
source/java/org/alfresco/repo/dictionary/TestModel.java
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.repo.dictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Test Model Definitions
|
||||
*/
|
||||
public class TestModel
|
||||
{
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
if (args != null && args.length > 0 && args[0].equals("-h"))
|
||||
{
|
||||
System.out.println("TestModel [model filename]*");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
System.out.println("Testing dictionary model definitions...");
|
||||
|
||||
// construct list of models to test
|
||||
// include alfresco defaults
|
||||
List<String> bootstrapModels = new ArrayList<String>();
|
||||
bootstrapModels.add("alfresco/model/dictionaryModel.xml");
|
||||
bootstrapModels.add("alfresco/model/systemModel.xml");
|
||||
bootstrapModels.add("alfresco/model/contentModel.xml");
|
||||
bootstrapModels.add("alfresco/model/applicationModel.xml");
|
||||
|
||||
// include models specified on command line
|
||||
for (String arg: args)
|
||||
{
|
||||
bootstrapModels.add(arg);
|
||||
}
|
||||
|
||||
for (String model : bootstrapModels)
|
||||
{
|
||||
System.out.println(" " + model);
|
||||
}
|
||||
|
||||
// construct dictionary dao
|
||||
NamespaceDAO namespaceDAO = new NamespaceDAOImpl();
|
||||
DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl(namespaceDAO);
|
||||
|
||||
// bootstrap dao
|
||||
try
|
||||
{
|
||||
DictionaryBootstrap bootstrap = new DictionaryBootstrap();
|
||||
bootstrap.setModels(bootstrapModels);
|
||||
bootstrap.setDictionaryDAO(dictionaryDAO);
|
||||
bootstrap.bootstrap();
|
||||
System.out.println("Models are valid.");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("Found an invalid model...");
|
||||
Throwable t = e;
|
||||
while (t != null)
|
||||
{
|
||||
System.out.println(t.getMessage());
|
||||
t = t.getCause();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
test_dictionarydaotest.description=Model Description
|
||||
|
||||
test_dictionarydaotest.class.test_base.title=Base Title
|
||||
test_dictionarydaotest.class.test_base.description=Base Description
|
||||
|
||||
test_dictionarydaotest.property.test_prop1.title=Prop1 Title
|
||||
test_dictionarydaotest.property.test_prop1.description=Prop1 Description
|
||||
|
||||
test_dictionarydaotest.association.test_assoc1.title=Assoc1 Title
|
||||
test_dictionarydaotest.association.test_assoc1.description=Assoc1 Description
|
||||
|
||||
test_dictionarydaotest.datatype.test_datatype.analyzer=Datatype Analyser
|
@@ -0,0 +1,148 @@
|
||||
<model name="test:dictionarydaotest" xmlns="http://www.alfresco.org/model/dictionary/1.0">
|
||||
|
||||
<description>Alfresco Content Model</description>
|
||||
<author>Alfresco</author>
|
||||
<published>2005-05-30</published>
|
||||
<version>1.0</version>
|
||||
|
||||
<imports>
|
||||
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
|
||||
</imports>
|
||||
|
||||
<namespaces>
|
||||
<namespace uri="http://www.alfresco.org/test/dictionarydaotest/1.0" prefix="test"/>
|
||||
</namespaces>
|
||||
|
||||
<data-types>
|
||||
|
||||
<data-type name="test:datatype">
|
||||
<analyser-class>org.apache.lucene.analysis.standard.StandardAnalyzer</analyser-class>
|
||||
<java-class>java.lang.Object</java-class>
|
||||
</data-type>
|
||||
|
||||
</data-types>
|
||||
|
||||
<types>
|
||||
|
||||
<type name="test:base">
|
||||
<title>Base</title>
|
||||
<description>The Base Type</description>
|
||||
<parent></parent>
|
||||
|
||||
<properties>
|
||||
<property name="test:prop1">
|
||||
<type>d:text</type>
|
||||
<protected>true</protected>
|
||||
<default></default>
|
||||
</property>
|
||||
</properties>
|
||||
|
||||
<associations>
|
||||
<association name="test:assoc1">
|
||||
<source>
|
||||
<mandatory>true</mandatory>
|
||||
<many>false</many>
|
||||
</source>
|
||||
<target>
|
||||
<class>test:base</class>
|
||||
<mandatory>false</mandatory>
|
||||
<many>true</many>
|
||||
</target>
|
||||
</association>
|
||||
<association name="test:assoc2">
|
||||
<source>
|
||||
<mandatory>true</mandatory>
|
||||
<many>true</many>
|
||||
</source>
|
||||
<target>
|
||||
<class>test:referenceable</class>
|
||||
<mandatory>false</mandatory>
|
||||
<many>false</many>
|
||||
</target>
|
||||
</association>
|
||||
<child-association name="test:childassoc1">
|
||||
<source>
|
||||
<mandatory>true</mandatory>
|
||||
<many>true</many>
|
||||
</source>
|
||||
<target>
|
||||
<class>test:referenceable</class>
|
||||
<mandatory>false</mandatory>
|
||||
<many>false</many>
|
||||
</target>
|
||||
<child-name>fred</child-name>
|
||||
<duplicate>true</duplicate>
|
||||
</child-association>
|
||||
</associations>
|
||||
|
||||
<mandatory-aspects>
|
||||
<aspect>test:referenceable</aspect>
|
||||
</mandatory-aspects>
|
||||
</type>
|
||||
|
||||
<type name="test:file">
|
||||
<parent>test:base</parent>
|
||||
|
||||
<properties>
|
||||
<property name="test:fileprop">
|
||||
<type>d:text</type>
|
||||
<protected>true</protected>
|
||||
<default></default>
|
||||
</property>
|
||||
|
||||
</properties>
|
||||
|
||||
<associations>
|
||||
<child-association name="test:childassoc2">
|
||||
<target>
|
||||
<class>test:referenceable</class>
|
||||
</target>
|
||||
<child-name>fred</child-name>
|
||||
<duplicate>true</duplicate>
|
||||
</child-association>
|
||||
</associations>
|
||||
|
||||
<overrides>
|
||||
<property name="test:prop">
|
||||
<default>an overriden default value</default>
|
||||
</property>
|
||||
</overrides>
|
||||
</type>
|
||||
|
||||
<type name="test:folder">
|
||||
<parent>test:base</parent>
|
||||
|
||||
<properties>
|
||||
<property name="test:folderprop">
|
||||
<type>d:text</type>
|
||||
<protected>true</protected>
|
||||
<default></default>
|
||||
</property>
|
||||
|
||||
</properties>
|
||||
|
||||
</type>
|
||||
|
||||
</types>
|
||||
|
||||
<aspects>
|
||||
<aspect name="test:referenceable">
|
||||
<title>Referenceable</title>
|
||||
<description>The referenceable aspect</description>
|
||||
<parent></parent>
|
||||
|
||||
<properties>
|
||||
<property name="test:id">
|
||||
<type>d:int</type>
|
||||
<protected>true</protected>
|
||||
<mandatory>true</mandatory>
|
||||
<index enabled="true">
|
||||
<atomic>true</atomic>
|
||||
<stored>false</stored>
|
||||
</index>
|
||||
</property>
|
||||
</properties>
|
||||
</aspect>
|
||||
</aspects>
|
||||
|
||||
</model>
|
134
source/java/org/alfresco/repo/dictionary/m2binding.xml
Normal file
134
source/java/org/alfresco/repo/dictionary/m2binding.xml
Normal file
@@ -0,0 +1,134 @@
|
||||
<binding>
|
||||
|
||||
<namespace uri="http://www.alfresco.org/model/dictionary/1.0" default="elements"/>
|
||||
|
||||
<format type="java.util.Date" serializer="org.alfresco.repo.dictionary.M2XML.serialiseDate" deserializer="org.alfresco.repo.dictionary.M2XML.deserialiseDate"/>
|
||||
|
||||
<mapping name="model" class="org.alfresco.repo.dictionary.M2Model">
|
||||
<value style="attribute" name="name" field="name"/>
|
||||
<value name="description" field="description" usage="optional"/>
|
||||
<value name="author" field="author" usage="optional"/>
|
||||
<value name="published" field="published" usage="optional"/>
|
||||
<value name="version" field="version" usage="optional"/>
|
||||
|
||||
<structure name="imports" usage="optional">
|
||||
<collection field="imports" factory="org.alfresco.repo.dictionary.M2Model.createList">
|
||||
<structure name="import" type="org.alfresco.repo.dictionary.M2Namespace" usage="optional">
|
||||
<value style="attribute" name="uri" field="uri"/>
|
||||
<value style="attribute" name="prefix" field="prefix"/>
|
||||
</structure>
|
||||
</collection>
|
||||
</structure>
|
||||
|
||||
<structure name="namespaces" usage="optional">
|
||||
<collection field="namespaces" factory="org.alfresco.repo.dictionary.M2Model.createList">
|
||||
<structure name="namespace" type="org.alfresco.repo.dictionary.M2Namespace" usage="optional">
|
||||
<value style="attribute" name="uri" field="uri"/>
|
||||
<value style="attribute" name="prefix" field="prefix"/>
|
||||
</structure>
|
||||
</collection>
|
||||
</structure>
|
||||
|
||||
<structure name="data-types" usage="optional">
|
||||
<collection field="dataTypes" factory="org.alfresco.repo.dictionary.M2Model.createList">
|
||||
<structure name="data-type" type="org.alfresco.repo.dictionary.M2DataType" usage="optional">
|
||||
<value style="attribute" name="name" field="name"/>
|
||||
<value name="title" field="title" usage="optional"/>
|
||||
<value name="description" field="description" usage="optional"/>
|
||||
<value name="analyser-class" field="analyserClassName"/>
|
||||
<value name="java-class" field="javaClassName"/>
|
||||
</structure>
|
||||
</collection>
|
||||
</structure>
|
||||
|
||||
<structure name="types" usage="optional">
|
||||
<collection field="types" item-type="org.alfresco.repo.dictionary.M2Type" factory="org.alfresco.repo.dictionary.M2Model.createList"/>
|
||||
</structure>
|
||||
|
||||
<structure name="aspects" usage="optional">
|
||||
<collection field="aspects" item-type="org.alfresco.repo.dictionary.M2Aspect" factory="org.alfresco.repo.dictionary.M2Model.createList"/>
|
||||
</structure>
|
||||
</mapping>
|
||||
|
||||
|
||||
<mapping class="org.alfresco.repo.dictionary.M2Class" abstract="true">
|
||||
<value style="attribute" name="name" field="name"/>
|
||||
<value name="title" field="title" usage="optional"/>
|
||||
<value name="description" field="description" usage="optional"/>
|
||||
<value name="parent" field="parentName" usage="optional"/>
|
||||
|
||||
<structure name="properties" usage="optional">
|
||||
<collection field="properties" item-type="org.alfresco.repo.dictionary.M2Property" factory="org.alfresco.repo.dictionary.M2Model.createList"/>
|
||||
</structure>
|
||||
<structure name="associations" usage="optional">
|
||||
<collection field="associations" factory="org.alfresco.repo.dictionary.M2Model.createList"/>
|
||||
</structure>
|
||||
<structure name="overrides" usage="optional">
|
||||
<collection field="propertyOverrides" item-type="org.alfresco.repo.dictionary.M2PropertyOverride" factory="org.alfresco.repo.dictionary.M2Model.createList">
|
||||
<structure name="property" type="org.alfresco.repo.dictionary.M2PropertyOverride" usage="optional">
|
||||
<value style="attribute" name="name" field="name"/>
|
||||
<value name="mandatory" field="isMandatory" usage="optional"/>
|
||||
<value name="default" field="defaultValue" usage="optional"/>
|
||||
</structure>
|
||||
</collection>
|
||||
</structure>
|
||||
<structure name="mandatory-aspects" usage="optional">
|
||||
<collection field="mandatoryAspects" factory="org.alfresco.repo.dictionary.M2Model.createList">
|
||||
<value name="aspect"/>
|
||||
</collection>
|
||||
</structure>
|
||||
</mapping>
|
||||
|
||||
<mapping name="type" class="org.alfresco.repo.dictionary.M2Type" extends="org.alfresco.repo.dictionary.M2Class">
|
||||
<structure map-as="org.alfresco.repo.dictionary.M2Class"/>
|
||||
</mapping>
|
||||
|
||||
<mapping name="aspect" class="org.alfresco.repo.dictionary.M2Aspect" extends="org.alfresco.repo.dictionary.M2Class">
|
||||
<structure map-as="org.alfresco.repo.dictionary.M2Class"/>
|
||||
</mapping>
|
||||
|
||||
<mapping name="property" class="org.alfresco.repo.dictionary.M2Property">
|
||||
<value style="attribute" name="name" field="name"/>
|
||||
<value name="title" field="title" usage="optional"/>
|
||||
<value name="description" field="description" usage="optional"/>
|
||||
<value name="type" field="propertyType"/>
|
||||
<value name="protected" field="isProtected" usage="optional"/>
|
||||
<value name="mandatory" field="isMandatory" usage="optional"/>
|
||||
<value name="multiple" field="isMultiValued" usage="optional"/>
|
||||
<value name="default" field="defaultValue" usage="optional"/>
|
||||
<structure name="index" usage="optional">
|
||||
<value style="attribute" name="enabled" field="isIndexed"/>
|
||||
<value name="atomic" field="isIndexedAtomically" usage="optional"/>
|
||||
<value name="stored" field="isStoredInIndex" usage="optional"/>
|
||||
<value name="tokenised" field="isTokenisedInIndex" usage="optional"/>
|
||||
</structure>
|
||||
</mapping>
|
||||
|
||||
<mapping class="org.alfresco.repo.dictionary.M2ClassAssociation" abstract="true">
|
||||
<value style="attribute" name="name" field="name"/>
|
||||
<value name="title" field="title" usage="optional"/>
|
||||
<value name="description" field="description" usage="optional"/>
|
||||
<structure name="source" usage="optional">
|
||||
<value name="role" field="sourceRoleName" usage="optional"/>
|
||||
<value name="mandatory" field="isSourceMandatory" usage="optional"/>
|
||||
<value name="many" field="isSourceMany" usage="optional"/>
|
||||
</structure>
|
||||
<structure name="target">
|
||||
<value name="class" field="targetClassName"/>
|
||||
<value name="role" field="targetRoleName" usage="optional"/>
|
||||
<value name="mandatory" field="isTargetMandatory" usage="optional"/>
|
||||
<value name="many" field="isTargetMany" usage="optional"/>
|
||||
</structure>
|
||||
</mapping>
|
||||
|
||||
<mapping name="association" class="org.alfresco.repo.dictionary.M2Association" extends="org.alfresco.repo.dictionary.M2ClassAssociation">
|
||||
<structure map-as="org.alfresco.repo.dictionary.M2ClassAssociation"/>
|
||||
</mapping>
|
||||
|
||||
<mapping name="child-association" class="org.alfresco.repo.dictionary.M2ChildAssociation" extends="org.alfresco.repo.dictionary.M2ClassAssociation">
|
||||
<structure map-as="org.alfresco.repo.dictionary.M2ClassAssociation"/>
|
||||
<value name="child-name" field="requiredChildName" usage="optional"/>
|
||||
<value name="duplicate" field="allowDuplicateChildName" usage="optional"/>
|
||||
</mapping>
|
||||
|
||||
</binding>
|
Reference in New Issue
Block a user