From bdae23b768d51013cc9412e6a83d22dd94b05aa6 Mon Sep 17 00:00:00 2001 From: Britt Park Date: Wed, 18 Apr 2007 23:25:53 +0000 Subject: [PATCH] Interim checkin. Attributes basically work. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5510 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/application-context.xml | 1 + .../alfresco/attributes-service-context.xml | 36 ++ config/alfresco/avm-services-context.xml | 6 + config/alfresco/hibernate-context.xml | 1 + config/alfresco/public-services-context.xml | 45 +++ .../alfresco/repo/attributes/Attribute.java | 1 - .../repo/attributes/AttributeConverter.java | 143 ++++++++ .../repo/attributes/AttributeImpl.java | 69 ++-- ...ava => AttributeMethodNotImplemented.java} | 4 +- .../repo/attributes/AttributeServiceImpl.java | 230 +++++++++++++ .../repo/attributes/AttributeServiceTest.java | 99 ++++++ .../repo/attributes/AttributeValue.java | 254 ++++++++++++++ .../repo/attributes/BooleanAttributeImpl.java | 20 +- .../attributes/BooleanAttributeValue.java | 74 ++++ .../repo/attributes/ByteAttributeImpl.java | 13 + ...Attribute.java => ByteAttributeValue.java} | 43 ++- .../repo/attributes/DoubleAttributeImpl.java | 13 + .../repo/attributes/DoubleAttributeValue.java | 74 ++++ .../repo/attributes/FloatAttributeImpl.java | 15 +- .../repo/attributes/FloatAttributeValue.java | 74 ++++ .../repo/attributes/GlobalAttributeEntry.java | 5 + .../attributes/GlobalAttributeEntryDAO.java | 4 +- .../attributes/GlobalAttributeEntryImpl.java | 4 + .../repo/attributes/IntAttributeImpl.java | 13 + ...ributeImpl.java => IntAttributeValue.java} | 33 +- .../repo/attributes/LongAttributeImpl.java | 13 + .../repo/attributes/LongAttributeValue.java | 73 ++++ .../repo/attributes/MapAttributeImpl.java | 92 ++++- .../repo/attributes/MapAttributeValue.java | 189 ++++++++++ .../alfresco/repo/attributes/MapEntry.java | 6 + .../repo/attributes/MapEntryImpl.java | 4 + .../attributes/SerializableAttributeImpl.java | 13 + .../SerializableAttributeValue.java | 76 ++++ .../repo/attributes/ShortAttributeImpl.java | 13 + .../repo/attributes/ShortAttributeValue.java | 74 ++++ .../repo/attributes/StringAttributeImpl.java | 13 + .../repo/attributes/StringAttributeValue.java | 74 ++++ .../org/alfresco/repo/attributes/Value.java | 256 -------------- .../alfresco/repo/attributes/ValueImpl.java | 325 ------------------ .../hibernate/AttributeDAOHibernate.java | 16 + .../attributes/hibernate/Attributes.hbm.xml | 28 +- .../GlobalAttributeEntryDAOHibernate.java | 6 +- .../cmr/attributes/AttributeService.java | 4 +- 43 files changed, 1891 insertions(+), 658 deletions(-) create mode 100644 config/alfresco/attributes-service-context.xml create mode 100644 source/java/org/alfresco/repo/attributes/AttributeConverter.java rename source/java/org/alfresco/repo/attributes/{ValueMethodNotImplementedException.java => AttributeMethodNotImplemented.java} (91%) create mode 100644 source/java/org/alfresco/repo/attributes/AttributeServiceImpl.java create mode 100644 source/java/org/alfresco/repo/attributes/AttributeServiceTest.java create mode 100644 source/java/org/alfresco/repo/attributes/AttributeValue.java create mode 100644 source/java/org/alfresco/repo/attributes/BooleanAttributeValue.java rename source/java/org/alfresco/repo/attributes/{BlobAttribute.java => ByteAttributeValue.java} (56%) create mode 100644 source/java/org/alfresco/repo/attributes/DoubleAttributeValue.java create mode 100644 source/java/org/alfresco/repo/attributes/FloatAttributeValue.java rename source/java/org/alfresco/repo/attributes/{BlobAttributeImpl.java => IntAttributeValue.java} (69%) create mode 100644 source/java/org/alfresco/repo/attributes/LongAttributeValue.java create mode 100644 source/java/org/alfresco/repo/attributes/MapAttributeValue.java create mode 100644 source/java/org/alfresco/repo/attributes/SerializableAttributeValue.java create mode 100644 source/java/org/alfresco/repo/attributes/ShortAttributeValue.java create mode 100644 source/java/org/alfresco/repo/attributes/StringAttributeValue.java delete mode 100644 source/java/org/alfresco/repo/attributes/Value.java delete mode 100644 source/java/org/alfresco/repo/attributes/ValueImpl.java diff --git a/config/alfresco/application-context.xml b/config/alfresco/application-context.xml index f3b1452f39..742df1c854 100644 --- a/config/alfresco/application-context.xml +++ b/config/alfresco/application-context.xml @@ -28,6 +28,7 @@ + diff --git a/config/alfresco/attributes-service-context.xml b/config/alfresco/attributes-service-context.xml new file mode 100644 index 0000000000..51a894b0cd --- /dev/null +++ b/config/alfresco/attributes-service-context.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config/alfresco/avm-services-context.xml b/config/alfresco/avm-services-context.xml index 30f24286f4..8f88502260 100644 --- a/config/alfresco/avm-services-context.xml +++ b/config/alfresco/avm-services-context.xml @@ -119,6 +119,12 @@ + + + + + + diff --git a/config/alfresco/hibernate-context.xml b/config/alfresco/hibernate-context.xml index 22b3444c45..a519a18fd7 100644 --- a/config/alfresco/hibernate-context.xml +++ b/config/alfresco/hibernate-context.xml @@ -46,6 +46,7 @@ org/alfresco/repo/domain/hibernate/AppliedPatch.hbm.xml org/alfresco/repo/domain/hibernate/Permission.hbm.xml org/alfresco/repo/avm/hibernate/AVM.hbm.xml + org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml diff --git a/config/alfresco/public-services-context.xml b/config/alfresco/public-services-context.xml index 7eaab5de4d..047d6caa06 100644 --- a/config/alfresco/public-services-context.xml +++ b/config/alfresco/public-services-context.xml @@ -890,6 +890,51 @@ + + + + + + + + + + getAttributes + query + + + + + + + + + + + + setAttribute + removeAttribute + + + + + + + + org.alfresco.service.cmr.attributes.AttributeService + + + + attributeService + + + + attributeServiceWriteTxnAdvisor + attributeServiceReadTxnAdvisor + + + + diff --git a/source/java/org/alfresco/repo/attributes/Attribute.java b/source/java/org/alfresco/repo/attributes/Attribute.java index dbd2c05ace..74c601a462 100644 --- a/source/java/org/alfresco/repo/attributes/Attribute.java +++ b/source/java/org/alfresco/repo/attributes/Attribute.java @@ -46,7 +46,6 @@ public interface Attribute extends Serializable FLOAT, DOUBLE, STRING, - BLOB, SERIALIZABLE, MAP }; diff --git a/source/java/org/alfresco/repo/attributes/AttributeConverter.java b/source/java/org/alfresco/repo/attributes/AttributeConverter.java new file mode 100644 index 0000000000..716ebe794c --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/AttributeConverter.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +import org.alfresco.error.AlfrescoRuntimeException; + +/** + * Handles conversions between persistent and value based Attributes. + * @author britt + */ +public class AttributeConverter +{ + /** + * Convert an Attribute (recursively) to a persistent attribute. This persists + * the newly created Attribute immediately. + * @param from The Attribute to clone. + * @return The cloned persistent Attribute. + */ + public Attribute toPersistent(Attribute from) + { + switch (from.getType()) + { + case BOOLEAN : + { + return new BooleanAttributeImpl((BooleanAttribute)from); + } + case BYTE : + { + return new ByteAttributeImpl((ByteAttribute)from); + } + case SHORT : + { + return new ShortAttributeImpl((ShortAttribute)from); + } + case INT : + { + return new IntAttributeImpl((IntAttribute)from); + } + case LONG : + { + return new LongAttributeImpl((LongAttribute)from); + } + case FLOAT : + { + return new FloatAttributeImpl((FloatAttribute)from); + } + case DOUBLE : + { + return new DoubleAttributeImpl((DoubleAttribute)from); + } + case STRING : + { + return new StringAttributeImpl((StringAttribute)from); + } + case SERIALIZABLE : + { + return new SerializableAttributeImpl((SerializableAttribute)from); + } + case MAP : + { + return new MapAttributeImpl((MapAttribute)from); + } + default : + { + throw new AlfrescoRuntimeException("Invalid Attribute Type: " + from.getType()); + } + } + } + + public Attribute toValue(Attribute from) + { + switch (from.getType()) + { + case BOOLEAN : + { + return new BooleanAttributeValue((BooleanAttribute)from); + } + case BYTE : + { + return new ByteAttributeValue((ByteAttribute)from); + } + case SHORT : + { + return new ShortAttributeValue((ShortAttribute)from); + } + case INT : + { + return new IntAttributeValue((IntAttribute)from); + } + case LONG : + { + return new LongAttributeValue((LongAttribute)from); + } + case FLOAT : + { + return new FloatAttributeValue((FloatAttribute)from); + } + case DOUBLE : + { + return new DoubleAttributeValue((DoubleAttribute)from); + } + case STRING : + { + return new StringAttributeValue((StringAttribute)from); + } + case SERIALIZABLE : + { + return new SerializableAttributeValue((SerializableAttribute)from); + } + case MAP : + { + return new MapAttributeValue((MapAttribute)from); + } + default : + { + throw new AlfrescoRuntimeException("Invalid Attribute Type: " + from.getType()); + } + } + } +} diff --git a/source/java/org/alfresco/repo/attributes/AttributeImpl.java b/source/java/org/alfresco/repo/attributes/AttributeImpl.java index 36b5366c49..91f01d38d0 100644 --- a/source/java/org/alfresco/repo/attributes/AttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/AttributeImpl.java @@ -41,6 +41,11 @@ public abstract class AttributeImpl implements Attribute */ private long fID; + /** + * The optimistic locking version. + */ + private long fVersion; + /** * Base constructor. */ @@ -58,12 +63,22 @@ public abstract class AttributeImpl implements Attribute return fID; } + public void setVersion(long version) + { + fVersion = version; + } + + public long getVersion() + { + return fVersion; + } + /* (non-Javadoc) * @see org.alfresco.repo.attributes.Value#clear() */ public void clear() { - throw new AtrributeMethodNotImplemented("Not ListValue or MapValue"); + throw new AttributeMethodNotImplemented("Not ListValue or MapValue"); } /* (non-Javadoc) @@ -71,7 +86,7 @@ public abstract class AttributeImpl implements Attribute */ public Set> entrySet() { - throw new AtrributeMethodNotImplemented("Not MapValue"); + throw new AttributeMethodNotImplemented("Not MapValue"); } /* (non-Javadoc) @@ -79,7 +94,7 @@ public abstract class AttributeImpl implements Attribute */ public Attribute get(String key) { - throw new AtrributeMethodNotImplemented("Not MapValue"); + throw new AttributeMethodNotImplemented("Not MapValue"); } /* (non-Javadoc) @@ -87,7 +102,7 @@ public abstract class AttributeImpl implements Attribute */ public byte[] getBlobValue() { - throw new AtrributeMethodNotImplemented("Not BlobValue"); + throw new AttributeMethodNotImplemented("Not BlobValue"); } /* (non-Javadoc) @@ -95,7 +110,7 @@ public abstract class AttributeImpl implements Attribute */ public double getDoubleValue() { - throw new AtrributeMethodNotImplemented("Not DoubleValue"); + throw new AttributeMethodNotImplemented("Not DoubleValue"); } /* (non-Javadoc) @@ -103,7 +118,7 @@ public abstract class AttributeImpl implements Attribute */ public int getIntValue() { - throw new AtrributeMethodNotImplemented("Not IntValue"); + throw new AttributeMethodNotImplemented("Not IntValue"); } /* (non-Javadoc) @@ -111,7 +126,7 @@ public abstract class AttributeImpl implements Attribute */ public long getLongValue() { - throw new AtrributeMethodNotImplemented("Not LongValue"); + throw new AttributeMethodNotImplemented("Not LongValue"); } /* (non-Javadoc) @@ -119,7 +134,7 @@ public abstract class AttributeImpl implements Attribute */ public Serializable getSerializableValue() { - throw new AtrributeMethodNotImplemented("Not SerializableValue"); + throw new AttributeMethodNotImplemented("Not SerializableValue"); } /* (non-Javadoc) @@ -127,7 +142,7 @@ public abstract class AttributeImpl implements Attribute */ public String getStringValue() { - throw new AtrributeMethodNotImplemented("Not StringValue"); + throw new AttributeMethodNotImplemented("Not StringValue"); } /* (non-Javadoc) @@ -135,7 +150,7 @@ public abstract class AttributeImpl implements Attribute */ public Set keySet() { - throw new AtrributeMethodNotImplemented("Not MapValue"); + throw new AttributeMethodNotImplemented("Not MapValue"); } /* (non-Javadoc) @@ -143,7 +158,7 @@ public abstract class AttributeImpl implements Attribute */ public void put(String key, Attribute value) { - throw new AtrributeMethodNotImplemented("Not MapValue"); + throw new AttributeMethodNotImplemented("Not MapValue"); } /* (non-Javadoc) @@ -151,7 +166,7 @@ public abstract class AttributeImpl implements Attribute */ public void remove(String key) { - throw new AtrributeMethodNotImplemented("Not MapValue"); + throw new AttributeMethodNotImplemented("Not MapValue"); } /* (non-Javadoc) @@ -159,7 +174,7 @@ public abstract class AttributeImpl implements Attribute */ public void setBlobValue(byte[] value) { - throw new AtrributeMethodNotImplemented("Not BlobValue"); + throw new AttributeMethodNotImplemented("Not BlobValue"); } /* (non-Javadoc) @@ -167,7 +182,7 @@ public abstract class AttributeImpl implements Attribute */ public void setDoubleValue(double value) { - throw new AtrributeMethodNotImplemented("Not DoubleValue"); + throw new AttributeMethodNotImplemented("Not DoubleValue"); } /* (non-Javadoc) @@ -175,7 +190,7 @@ public abstract class AttributeImpl implements Attribute */ public void setIntValue(int value) { - throw new AtrributeMethodNotImplemented("Not IntValue"); + throw new AttributeMethodNotImplemented("Not IntValue"); } /* (non-Javadoc) @@ -183,7 +198,7 @@ public abstract class AttributeImpl implements Attribute */ public void setLongValue(long value) { - throw new AtrributeMethodNotImplemented("Not LongValue"); + throw new AttributeMethodNotImplemented("Not LongValue"); } /* (non-Javadoc) @@ -191,7 +206,7 @@ public abstract class AttributeImpl implements Attribute */ public void setSerializableValue(Serializable value) { - throw new AtrributeMethodNotImplemented("Not SerializableValue"); + throw new AttributeMethodNotImplemented("Not SerializableValue"); } /* (non-Javadoc) @@ -199,7 +214,7 @@ public abstract class AttributeImpl implements Attribute */ public void setStringValue(String value) { - throw new AtrributeMethodNotImplemented("Not StringValue"); + throw new AttributeMethodNotImplemented("Not StringValue"); } /* (non-Javadoc) @@ -207,7 +222,7 @@ public abstract class AttributeImpl implements Attribute */ public Collection values() { - throw new AtrributeMethodNotImplemented("Not MapValue"); + throw new AttributeMethodNotImplemented("Not MapValue"); } /* (non-Javadoc) @@ -215,7 +230,7 @@ public abstract class AttributeImpl implements Attribute */ public boolean getBooleanValue() { - throw new AtrributeMethodNotImplemented("Not BooleanValue"); + throw new AttributeMethodNotImplemented("Not BooleanValue"); } /* (non-Javadoc) @@ -223,7 +238,7 @@ public abstract class AttributeImpl implements Attribute */ public byte getByteValue() { - throw new AtrributeMethodNotImplemented("Not ByteValue"); + throw new AttributeMethodNotImplemented("Not ByteValue"); } /* (non-Javadoc) @@ -231,7 +246,7 @@ public abstract class AttributeImpl implements Attribute */ public float getFloatValue() { - throw new AtrributeMethodNotImplemented("Not FloatValue"); + throw new AttributeMethodNotImplemented("Not FloatValue"); } /* (non-Javadoc) @@ -239,7 +254,7 @@ public abstract class AttributeImpl implements Attribute */ public short getShortValue() { - throw new AtrributeMethodNotImplemented("Not ShortValue"); + throw new AttributeMethodNotImplemented("Not ShortValue"); } /* (non-Javadoc) @@ -247,7 +262,7 @@ public abstract class AttributeImpl implements Attribute */ public void setBooleanValue(boolean value) { - throw new AtrributeMethodNotImplemented("Not BooleanValue"); + throw new AttributeMethodNotImplemented("Not BooleanValue"); } /* (non-Javadoc) @@ -255,7 +270,7 @@ public abstract class AttributeImpl implements Attribute */ public void setByteValue(byte value) { - throw new AtrributeMethodNotImplemented("Not ByteValue"); + throw new AttributeMethodNotImplemented("Not ByteValue"); } /* (non-Javadoc) @@ -263,7 +278,7 @@ public abstract class AttributeImpl implements Attribute */ public void setFloatValue(float value) { - throw new AtrributeMethodNotImplemented("Not FloatValue"); + throw new AttributeMethodNotImplemented("Not FloatValue"); } /* (non-Javadoc) @@ -271,6 +286,6 @@ public abstract class AttributeImpl implements Attribute */ public void setShortValue(short value) { - throw new AtrributeMethodNotImplemented("Not ShortValue"); + throw new AttributeMethodNotImplemented("Not ShortValue"); } } diff --git a/source/java/org/alfresco/repo/attributes/ValueMethodNotImplementedException.java b/source/java/org/alfresco/repo/attributes/AttributeMethodNotImplemented.java similarity index 91% rename from source/java/org/alfresco/repo/attributes/ValueMethodNotImplementedException.java rename to source/java/org/alfresco/repo/attributes/AttributeMethodNotImplemented.java index 8edcf2a696..debdcecb5f 100644 --- a/source/java/org/alfresco/repo/attributes/ValueMethodNotImplementedException.java +++ b/source/java/org/alfresco/repo/attributes/AttributeMethodNotImplemented.java @@ -31,11 +31,11 @@ import org.alfresco.error.AlfrescoRuntimeException; * For unimplemented attribute methods. * @author britt */ -public class ValueMethodNotImplementedException extends AlfrescoRuntimeException +public class AttributeMethodNotImplemented extends AlfrescoRuntimeException { private static final long serialVersionUID = -7167699355451456957L; - public ValueMethodNotImplementedException(String message) + public AttributeMethodNotImplemented(String message) { super(message); } diff --git a/source/java/org/alfresco/repo/attributes/AttributeServiceImpl.java b/source/java/org/alfresco/repo/attributes/AttributeServiceImpl.java new file mode 100644 index 0000000000..f8516aef76 --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/AttributeServiceImpl.java @@ -0,0 +1,230 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.repo.attributes.Attribute.Type; +import org.alfresco.service.cmr.attributes.AttrQuery; +import org.alfresco.service.cmr.attributes.AttributeService; +import org.alfresco.service.cmr.avm.AVMBadArgumentException; +import org.alfresco.service.cmr.avm.AVMNotFoundException; +import org.alfresco.service.cmr.avm.AVMWrongTypeException; + +/** + * Implementation of the AttributeService interface. + * @author britt + */ +public class AttributeServiceImpl implements AttributeService +{ + private GlobalAttributeEntryDAO fGlobalAttributeEntryDAO; + + private AttributeConverter fAttributeConverter; + + public AttributeServiceImpl() + { + } + + public void setGlobalAttributeEntryDao(GlobalAttributeEntryDAO dao) + { + fGlobalAttributeEntryDAO = dao; + } + + public void setAttributeConverter(AttributeConverter converter) + { + fAttributeConverter = converter; + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.attributes.AttributeService#getAttribute(java.lang.String) + */ + public Attribute getAttribute(String path) + { + if (path == null) + { + throw new AVMBadArgumentException("Null path."); + } + List keys = parsePath(path); + if (keys.size() < 1) + { + throw new AVMBadArgumentException("Bad Attribute Path: " + path); + } + GlobalAttributeEntry entry = fGlobalAttributeEntryDAO.get(keys.get(0)); + if (entry == null) + { + return null; + } + Attribute current = entry.getAttribute(); + for (int i = 1; i < keys.size(); i++) + { + if (current.getType() != Type.MAP) + { + return null; + } + current = current.get(keys.get(i)); + if (current == null) + { + return null; + } + } + return fAttributeConverter.toValue(current); + } + + /** + * Utility to parse paths. Paths are of the form '/name/name'. '\' can + * be used to escape '/'s. + * @param path The path to parse. + * @return The components of the path. + */ + private List parsePath(String path) + { + List components = new ArrayList(); + int off = 0; + while (off < path.length()) + { + while (off < path.length() && path.charAt(off) == '/') + { + off++; + } + StringBuilder builder = new StringBuilder(); + while (off < path.length()) + { + char c = path.charAt(off); + if (c == '/') + { + break; + } + if (c == '\\') + { + off++; + if (off >= path.length()) + { + break; + } + c = path.charAt(off); + } + builder.append(c); + off++; + } + components.add(builder.toString()); + } + return components; + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.attributes.AttributeService#query(java.lang.String, org.alfresco.service.cmr.attributes.AttrQuery) + */ + public List query(String path, AttrQuery query) + { + return null; + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.attributes.AttributeService#removeAttribute(java.lang.String) + */ + public void removeAttribute(String path, String name) + { + if (path == null) + { + throw new AVMBadArgumentException("Null Attribute Path."); + } + List keys = parsePath(path); + if (keys.size() == 0) + { + fGlobalAttributeEntryDAO.delete(name); + return; + } + GlobalAttributeEntry entry = fGlobalAttributeEntryDAO.get(keys.get(0)); + if (entry == null) + { + throw new AVMNotFoundException("Attribute Not Found: " + keys.get(0)); + } + Attribute current = entry.getAttribute(); + if (current.getType() != Type.MAP) + { + throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(0)); + } + for (int i = 1; i < keys.size(); i++) + { + current = current.get(keys.get(i)); + if (current == null) + { + throw new AVMNotFoundException("Attribute Not Found: " + keys.get(i)); + } + if (current.getType() != Type.MAP) + { + throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(i)); + } + } + current.remove(name); + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.attributes.AttributeService#setAttribute(java.lang.String, org.alfresco.repo.attributes.Attribute) + */ + public void setAttribute(String path, String name, Attribute value) + { + List keys = parsePath(path); + Attribute toSave = fAttributeConverter.toPersistent(value); + if (keys.size() == 0) + { + GlobalAttributeEntry found = fGlobalAttributeEntryDAO.get(name); + if (found == null) + { + found = new GlobalAttributeEntryImpl(name, toSave); + fGlobalAttributeEntryDAO.save(found); + return; + } + found.setAttribute(toSave); + return; + } + GlobalAttributeEntry gEntry = fGlobalAttributeEntryDAO.get(keys.get(0)); + if (gEntry == null) + { + throw new AVMNotFoundException("Global Attribute Not Found: " + keys.get(0)); + } + Attribute current = gEntry.getAttribute(); + if (current.getType() != Type.MAP) + { + throw new AVMWrongTypeException("Global Attribute Not Map: " + keys.get(0)); + } + for (int i = 1; i < keys.size(); i++) + { + Attribute child = current.get(keys.get(i)); + if (child == null) + { + throw new AVMNotFoundException("Attribute Not Found: " + keys.get(i)); + } + if (child.getType() != Type.MAP) + { + throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(i)); + } + current = child; + } + current.put(name, toSave); + } +} diff --git a/source/java/org/alfresco/repo/attributes/AttributeServiceTest.java b/source/java/org/alfresco/repo/attributes/AttributeServiceTest.java new file mode 100644 index 0000000000..06a3d425de --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/AttributeServiceTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +import org.alfresco.service.cmr.attributes.AttributeService; +import org.springframework.context.support.FileSystemXmlApplicationContext; + +import junit.framework.TestCase; + +/** + * Basic tests for AttributeService. + * @author britt + */ +public class AttributeServiceTest extends TestCase +{ + private FileSystemXmlApplicationContext fContext = null; + + private AttributeService fService; + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception + { + if (fContext == null) + { + fContext = new FileSystemXmlApplicationContext("config/alfresco/application-context.xml"); + fService = (AttributeService)fContext.getBean("AttributeService"); + } + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#tearDown() + */ + @Override + protected void tearDown() throws Exception + { + fContext.close(); + fContext = null; + } + + public void testBasic() + { + try + { + fService.setAttribute("", "boolean", new BooleanAttributeValue(true)); + fService.setAttribute("", "byte", new ByteAttributeValue((byte)0x20)); + fService.setAttribute("", "short", new ShortAttributeValue((short)42)); + fService.setAttribute("", "int", new IntAttributeValue(43)); + fService.setAttribute("", "long", new LongAttributeValue(1000000000000L)); + fService.setAttribute("", "float", new FloatAttributeValue(1.414f)); + fService.setAttribute("", "double", new DoubleAttributeValue(3.1415926)); + fService.setAttribute("", "string", new StringAttributeValue("This is a string.")); + fService.setAttribute("", "serializable", new SerializableAttributeValue(new Long(1010101L))); + MapAttribute map = new MapAttributeValue(); + map.put("foo", new StringAttributeValue("I walk.")); + map.put("bar", new StringAttributeValue("I talk.")); + map.put("baz", new StringAttributeValue("I shop.")); + map.put("funky", new StringAttributeValue("I sneeze.")); + map.put("monkey", + new StringAttributeValue("I'm going to be a fireman when the floods roll back.")); + fService.setAttribute("", "map", map); + assertNotNull(fService.getAttribute("boolean")); + assertEquals(42, (int)fService.getAttribute("short").getShortValue()); + assertEquals("I sneeze.", fService.getAttribute("map/funky").getStringValue()); + Attribute found = fService.getAttribute("map"); + System.out.println(found); + } + catch (Exception e) + { + e.printStackTrace(); + fail(); + } + } +} diff --git a/source/java/org/alfresco/repo/attributes/AttributeValue.java b/source/java/org/alfresco/repo/attributes/AttributeValue.java new file mode 100644 index 0000000000..c7540e23de --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/AttributeValue.java @@ -0,0 +1,254 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +import java.io.Serializable; +import java.util.Collection; +import java.util.Set; +import java.util.Map.Entry; + +/** + * Value based non-persistent implementation of Attribute. + * @author britt + */ +public abstract class AttributeValue implements Attribute +{ + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#clear() + */ + public void clear() + { + throw new AttributeMethodNotImplemented("Not a Map."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#entrySet() + */ + public Set> entrySet() + { + throw new AttributeMethodNotImplemented("Not a Map."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#get(java.lang.String) + */ + public Attribute get(String key) + { + throw new AttributeMethodNotImplemented("Not a Map."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getBlobValue() + */ + public byte[] getBlobValue() + { + throw new AttributeMethodNotImplemented("Not a Blob."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getBooleanValue() + */ + public boolean getBooleanValue() + { + throw new AttributeMethodNotImplemented("Not a boolean."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getByteValue() + */ + public byte getByteValue() + { + throw new AttributeMethodNotImplemented("Not a byte."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getDoubleValue() + */ + public double getDoubleValue() + { + throw new AttributeMethodNotImplemented("Not a double."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getFloatValue() + */ + public float getFloatValue() + { + throw new AttributeMethodNotImplemented("Not a float."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getIntValue() + */ + public int getIntValue() + { + throw new AttributeMethodNotImplemented("Not an int."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getLongValue() + */ + public long getLongValue() + { + throw new AttributeMethodNotImplemented("Not a long."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getSerializableValue() + */ + public Serializable getSerializableValue() + { + throw new AttributeMethodNotImplemented("Not a Serializable."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getShortValue() + */ + public short getShortValue() + { + throw new AttributeMethodNotImplemented("Not a short."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getStringValue() + */ + public String getStringValue() + { + throw new AttributeMethodNotImplemented("Not a String."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#keySet() + */ + public Set keySet() + { + throw new AttributeMethodNotImplemented("Not a map."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#put(java.lang.String, org.alfresco.repo.attributes.Attribute) + */ + public void put(String key, Attribute value) + { + throw new AttributeMethodNotImplemented("Not a map."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#remove(java.lang.String) + */ + public void remove(String key) + { + throw new AttributeMethodNotImplemented("Not a map."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#setBlobValue(byte[]) + */ + public void setBlobValue(byte[] value) + { + throw new AttributeMethodNotImplemented("Not a Blob."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#setBooleanValue(boolean) + */ + public void setBooleanValue(boolean value) + { + throw new AttributeMethodNotImplemented("Not a boolean."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#setByteValue(byte) + */ + public void setByteValue(byte value) + { + throw new AttributeMethodNotImplemented("Not a byte."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#setDoubleValue(double) + */ + public void setDoubleValue(double value) + { + throw new AttributeMethodNotImplemented("Not a double."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#setFloatValue(float) + */ + public void setFloatValue(float value) + { + throw new AttributeMethodNotImplemented("Not a float."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#setIntValue(int) + */ + public void setIntValue(int value) + { + throw new AttributeMethodNotImplemented("Not an int."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#setLongValue(long) + */ + public void setLongValue(long value) + { + throw new AttributeMethodNotImplemented("Not a long."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#setSerializableValue(java.io.Serializable) + */ + public void setSerializableValue(Serializable value) + { + throw new AttributeMethodNotImplemented("Not a Serializable."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#setShortValue(short) + */ + public void setShortValue(short value) + { + throw new AttributeMethodNotImplemented("Not a short."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#setStringValue(java.lang.String) + */ + public void setStringValue(String value) + { + throw new AttributeMethodNotImplemented("Not a String."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#values() + */ + public Collection values() + { + throw new AttributeMethodNotImplemented("Not a map."); + } +} diff --git a/source/java/org/alfresco/repo/attributes/BooleanAttributeImpl.java b/source/java/org/alfresco/repo/attributes/BooleanAttributeImpl.java index 1f88241e7a..a22f006dbd 100644 --- a/source/java/org/alfresco/repo/attributes/BooleanAttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/BooleanAttributeImpl.java @@ -25,6 +25,8 @@ package org.alfresco.repo.attributes; +import org.alfresco.repo.avm.AVMDAOs; + /** * @author britt * @@ -35,6 +37,22 @@ public class BooleanAttributeImpl extends AttributeImpl implements private static final long serialVersionUID = 8483440613101900682L; private boolean fValue; + + public BooleanAttributeImpl() + { + } + + public BooleanAttributeImpl(boolean value) + { + fValue = value; + AVMDAOs.Instance().fAttributeDAO.save(this); + } + + public BooleanAttributeImpl(BooleanAttribute attr) + { + fValue = attr.getBooleanValue(); + AVMDAOs.Instance().fAttributeDAO.save(this); + } /* (non-Javadoc) * @see org.alfresco.repo.attributes.AttributeImpl#getBooleanValue() @@ -44,7 +62,7 @@ public class BooleanAttributeImpl extends AttributeImpl implements { return fValue; } - + /* (non-Javadoc) * @see org.alfresco.repo.attributes.AttributeImpl#setBooleanValue(boolean) */ diff --git a/source/java/org/alfresco/repo/attributes/BooleanAttributeValue.java b/source/java/org/alfresco/repo/attributes/BooleanAttributeValue.java new file mode 100644 index 0000000000..204a07611d --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/BooleanAttributeValue.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +/** + * Value based implementation of a boolean attribute. + * @author britt + */ +public class BooleanAttributeValue extends AttributeValue implements + BooleanAttribute +{ + private static final long serialVersionUID = 4019402783943642209L; + + private boolean fData; + + public BooleanAttributeValue(boolean value) + { + fData = value; + } + + public BooleanAttributeValue(BooleanAttribute attr) + { + fData = attr.getBooleanValue(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getType() + */ + public Type getType() + { + return Type.BOOLEAN; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#getBooleanValue() + */ + @Override + public boolean getBooleanValue() + { + return fData; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#setBooleanValue(boolean) + */ + @Override + public void setBooleanValue(boolean value) + { + fData = value; + } +} diff --git a/source/java/org/alfresco/repo/attributes/ByteAttributeImpl.java b/source/java/org/alfresco/repo/attributes/ByteAttributeImpl.java index 483aae850e..1917cbc845 100644 --- a/source/java/org/alfresco/repo/attributes/ByteAttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/ByteAttributeImpl.java @@ -25,6 +25,8 @@ package org.alfresco.repo.attributes; +import org.alfresco.repo.avm.AVMDAOs; + /** * A Byte Attribute. * @author britt @@ -35,11 +37,22 @@ public class ByteAttributeImpl extends AttributeImpl implements ByteAttribute private byte fValue; + public ByteAttributeImpl() + { + } + public ByteAttributeImpl(byte value) { fValue = value; + AVMDAOs.Instance().fAttributeDAO.save(this); } + public ByteAttributeImpl(ByteAttribute attr) + { + fValue = attr.getByteValue(); + AVMDAOs.Instance().fAttributeDAO.save(this); + } + /* (non-Javadoc) * @see org.alfresco.repo.attributes.Attribute#getType() */ diff --git a/source/java/org/alfresco/repo/attributes/BlobAttribute.java b/source/java/org/alfresco/repo/attributes/ByteAttributeValue.java similarity index 56% rename from source/java/org/alfresco/repo/attributes/BlobAttribute.java rename to source/java/org/alfresco/repo/attributes/ByteAttributeValue.java index 63c090964e..9cfd4899b7 100644 --- a/source/java/org/alfresco/repo/attributes/BlobAttribute.java +++ b/source/java/org/alfresco/repo/attributes/ByteAttributeValue.java @@ -26,9 +26,48 @@ package org.alfresco.repo.attributes; /** - * Placeholder interface for Blob attributes. + * Value based implementation of byte attribute. * @author britt */ -public interface BlobAttribute extends Attribute +public class ByteAttributeValue extends AttributeValue implements ByteAttribute { + private static final long serialVersionUID = -5011945743563985072L; + + private byte fData; + + public ByteAttributeValue(byte value) + { + fData = value; + } + + public ByteAttributeValue(ByteAttribute attr) + { + fData = attr.getByteValue(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getType() + */ + public Type getType() + { + return Type.BYTE; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#getByteValue() + */ + @Override + public byte getByteValue() + { + return fData; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#setByteValue(byte) + */ + @Override + public void setByteValue(byte value) + { + fData = value; + } } diff --git a/source/java/org/alfresco/repo/attributes/DoubleAttributeImpl.java b/source/java/org/alfresco/repo/attributes/DoubleAttributeImpl.java index 917de389f4..c1a265a91f 100644 --- a/source/java/org/alfresco/repo/attributes/DoubleAttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/DoubleAttributeImpl.java @@ -25,6 +25,8 @@ package org.alfresco.repo.attributes; +import org.alfresco.repo.avm.AVMDAOs; + /** * @author britt * @@ -35,9 +37,20 @@ public class DoubleAttributeImpl extends AttributeImpl implements Attribute private double fValue; + public DoubleAttributeImpl() + { + } + public DoubleAttributeImpl(double value) { fValue = value; + AVMDAOs.Instance().fAttributeDAO.save(this); + } + + public DoubleAttributeImpl(DoubleAttribute attr) + { + fValue = attr.getDoubleValue(); + AVMDAOs.Instance().fAttributeDAO.save(this); } /* (non-Javadoc) diff --git a/source/java/org/alfresco/repo/attributes/DoubleAttributeValue.java b/source/java/org/alfresco/repo/attributes/DoubleAttributeValue.java new file mode 100644 index 0000000000..e7ea466577 --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/DoubleAttributeValue.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +/** + * Value based implementation of a double attribute. + * @author britt + */ +public class DoubleAttributeValue extends AttributeValue implements + DoubleAttribute +{ + private static final long serialVersionUID = 1710813761810342910L; + + private double fData; + + public DoubleAttributeValue(double value) + { + fData = value; + } + + public DoubleAttributeValue(DoubleAttribute attr) + { + fData = attr.getDoubleValue(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getType() + */ + public Type getType() + { + return Type.DOUBLE; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#getDoubleValue() + */ + @Override + public double getDoubleValue() + { + return fData; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#setDoubleValue(double) + */ + @Override + public void setDoubleValue(double value) + { + fData = value; + } +} diff --git a/source/java/org/alfresco/repo/attributes/FloatAttributeImpl.java b/source/java/org/alfresco/repo/attributes/FloatAttributeImpl.java index d8c897f7b2..dabb2dc96f 100644 --- a/source/java/org/alfresco/repo/attributes/FloatAttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/FloatAttributeImpl.java @@ -25,9 +25,11 @@ package org.alfresco.repo.attributes; +import org.alfresco.repo.avm.AVMDAOs; + /** + * Persistent implementation of float attribute. * @author britt - * */ public class FloatAttributeImpl extends AttributeImpl implements FloatAttribute { @@ -35,9 +37,20 @@ public class FloatAttributeImpl extends AttributeImpl implements FloatAttribute private float fValue; + public FloatAttributeImpl() + { + } + public FloatAttributeImpl(float value) { fValue = value; + AVMDAOs.Instance().fAttributeDAO.save(this); + } + + public FloatAttributeImpl(FloatAttribute attr) + { + fValue = attr.getFloatValue(); + AVMDAOs.Instance().fAttributeDAO.save(this); } /* (non-Javadoc) diff --git a/source/java/org/alfresco/repo/attributes/FloatAttributeValue.java b/source/java/org/alfresco/repo/attributes/FloatAttributeValue.java new file mode 100644 index 0000000000..0c2c2a42dc --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/FloatAttributeValue.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +/** + * Value based implementation of float attribute + * @author britt + */ +public class FloatAttributeValue extends AttributeValue implements + FloatAttribute +{ + private static final long serialVersionUID = -1645099708530314562L; + + private float fData; + + public FloatAttributeValue(float value) + { + fData = value; + } + + public FloatAttributeValue(FloatAttribute attr) + { + fData = attr.getFloatValue(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getType() + */ + public Type getType() + { + return Type.FLOAT; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#getFloatValue() + */ + @Override + public float getFloatValue() + { + return fData; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#setFloatValue(float) + */ + @Override + public void setFloatValue(float value) + { + fData = value; + } +} diff --git a/source/java/org/alfresco/repo/attributes/GlobalAttributeEntry.java b/source/java/org/alfresco/repo/attributes/GlobalAttributeEntry.java index 7cdaec8d73..b62441afa6 100644 --- a/source/java/org/alfresco/repo/attributes/GlobalAttributeEntry.java +++ b/source/java/org/alfresco/repo/attributes/GlobalAttributeEntry.java @@ -40,4 +40,9 @@ public interface GlobalAttributeEntry * Get the Attribute. */ public Attribute getAttribute(); + + /** + * Set the Attribute. + */ + public void setAttribute(Attribute attr); } diff --git a/source/java/org/alfresco/repo/attributes/GlobalAttributeEntryDAO.java b/source/java/org/alfresco/repo/attributes/GlobalAttributeEntryDAO.java index aac5a440ad..7832079881 100644 --- a/source/java/org/alfresco/repo/attributes/GlobalAttributeEntryDAO.java +++ b/source/java/org/alfresco/repo/attributes/GlobalAttributeEntryDAO.java @@ -27,7 +27,7 @@ public interface GlobalAttributeEntryDAO /** * Get an attribute by name. * @param name The name of the attribute. - * @return The attribute or null. + * @return The entry or null. */ - public Attribute get(String name); + public GlobalAttributeEntry get(String name); } diff --git a/source/java/org/alfresco/repo/attributes/GlobalAttributeEntryImpl.java b/source/java/org/alfresco/repo/attributes/GlobalAttributeEntryImpl.java index 816d4a31ce..0ea677d0a6 100644 --- a/source/java/org/alfresco/repo/attributes/GlobalAttributeEntryImpl.java +++ b/source/java/org/alfresco/repo/attributes/GlobalAttributeEntryImpl.java @@ -35,6 +35,10 @@ public class GlobalAttributeEntryImpl implements GlobalAttributeEntry private Attribute fAttribute; + public GlobalAttributeEntryImpl() + { + } + public GlobalAttributeEntryImpl(String name, Attribute attr) { fName = name; diff --git a/source/java/org/alfresco/repo/attributes/IntAttributeImpl.java b/source/java/org/alfresco/repo/attributes/IntAttributeImpl.java index f579e5b63d..26cf6c3e19 100644 --- a/source/java/org/alfresco/repo/attributes/IntAttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/IntAttributeImpl.java @@ -25,6 +25,8 @@ package org.alfresco.repo.attributes; +import org.alfresco.repo.avm.AVMDAOs; + /** * An integer attribute. * @author britt @@ -35,9 +37,20 @@ public class IntAttributeImpl extends AttributeImpl implements IntAttribute private int fValue; + public IntAttributeImpl() + { + } + public IntAttributeImpl(int value) { fValue = value; + AVMDAOs.Instance().fAttributeDAO.save(this); + } + + public IntAttributeImpl(IntAttribute attr) + { + fValue = attr.getIntValue(); + AVMDAOs.Instance().fAttributeDAO.save(this); } /* (non-Javadoc) diff --git a/source/java/org/alfresco/repo/attributes/BlobAttributeImpl.java b/source/java/org/alfresco/repo/attributes/IntAttributeValue.java similarity index 69% rename from source/java/org/alfresco/repo/attributes/BlobAttributeImpl.java rename to source/java/org/alfresco/repo/attributes/IntAttributeValue.java index e929ac5175..efe4723f4e 100644 --- a/source/java/org/alfresco/repo/attributes/BlobAttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/IntAttributeValue.java @@ -26,18 +26,23 @@ package org.alfresco.repo.attributes; /** - * Persistent implementation of Blob attribute. + * Value based implementation of int attribute. * @author britt */ -public class BlobAttributeImpl extends AttributeImpl implements BlobAttribute +public class IntAttributeValue extends AttributeValue implements IntAttribute { - private static final long serialVersionUID = 53323685626921588L; + private static final long serialVersionUID = -7547112946658496030L; - private byte[] fValue; - - public BlobAttributeImpl(byte[] value) + private int fData; + + public IntAttributeValue(int value) { - fValue = value; + fData = value; + } + + public IntAttributeValue(IntAttribute attr) + { + fData = attr.getIntValue(); } /* (non-Javadoc) @@ -45,24 +50,24 @@ public class BlobAttributeImpl extends AttributeImpl implements BlobAttribute */ public Type getType() { - return Type.BLOB; + return Type.INT; } /* (non-Javadoc) - * @see org.alfresco.repo.attributes.AttributeImpl#getBlobValue() + * @see org.alfresco.repo.attributes.AttributeValue#getIntValue() */ @Override - public byte[] getBlobValue() + public int getIntValue() { - return fValue; + return fData; } /* (non-Javadoc) - * @see org.alfresco.repo.attributes.AttributeImpl#setBlobValue(byte[]) + * @see org.alfresco.repo.attributes.AttributeValue#setIntValue(int) */ @Override - public void setBlobValue(byte[] value) + public void setIntValue(int value) { - fValue = value; + fData = value; } } diff --git a/source/java/org/alfresco/repo/attributes/LongAttributeImpl.java b/source/java/org/alfresco/repo/attributes/LongAttributeImpl.java index c21c72b777..e162f25c58 100644 --- a/source/java/org/alfresco/repo/attributes/LongAttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/LongAttributeImpl.java @@ -25,6 +25,8 @@ package org.alfresco.repo.attributes; +import org.alfresco.repo.avm.AVMDAOs; + /** * Long valued attribute. * @author britt @@ -35,9 +37,20 @@ public class LongAttributeImpl extends AttributeImpl implements LongAttribute private long fValue; + public LongAttributeImpl() + { + } + public LongAttributeImpl(long value) { fValue = value; + AVMDAOs.Instance().fAttributeDAO.save(this); + } + + public LongAttributeImpl(LongAttribute attr) + { + fValue = attr.getLongValue(); + AVMDAOs.Instance().fAttributeDAO.save(this); } /* (non-Javadoc) diff --git a/source/java/org/alfresco/repo/attributes/LongAttributeValue.java b/source/java/org/alfresco/repo/attributes/LongAttributeValue.java new file mode 100644 index 0000000000..30df53af0b --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/LongAttributeValue.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +/** + * Value based implementation of a long attribute. + * @author britt + */ +public class LongAttributeValue extends AttributeValue implements LongAttribute +{ + private static final long serialVersionUID = 3978001405238962585L; + + private long fData; + + public LongAttributeValue(long value) + { + fData = value; + } + + public LongAttributeValue(LongAttribute attr) + { + fData = attr.getLongValue(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getType() + */ + public Type getType() + { + return Type.LONG; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#getLongValue() + */ + @Override + public long getLongValue() + { + return fData; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#setLongValue(long) + */ + @Override + public void setLongValue(long value) + { + fData = value; + } +} diff --git a/source/java/org/alfresco/repo/attributes/MapAttributeImpl.java b/source/java/org/alfresco/repo/attributes/MapAttributeImpl.java index ae0d9dea3c..feea296458 100644 --- a/source/java/org/alfresco/repo/attributes/MapAttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/MapAttributeImpl.java @@ -34,18 +34,91 @@ import java.util.Map; import java.util.Set; import java.util.Map.Entry; +import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.avm.AVMDAOs; +import org.alfresco.service.cmr.avm.AVMNotFoundException; /** + * Persistent map attribute implementation. * @author britt - * */ public class MapAttributeImpl extends AttributeImpl implements MapAttribute { + private static final long serialVersionUID = -2627849542488029248L; + public MapAttributeImpl() { } + public MapAttributeImpl(MapAttribute attr) + { + AVMDAOs.Instance().fAttributeDAO.save(this); + for (Map.Entry entry : attr.entrySet()) + { + Attribute value = entry.getValue(); + Attribute newAttr = null; + switch (value.getType()) + { + case BOOLEAN : + { + newAttr = new BooleanAttributeImpl(value.getBooleanValue()); + break; + } + case BYTE : + { + newAttr = new ByteAttributeImpl(value.getByteValue()); + break; + } + case SHORT : + { + newAttr = new ShortAttributeImpl(value.getShortValue()); + break; + } + case INT : + { + newAttr = new IntAttributeImpl(value.getIntValue()); + break; + } + case LONG : + { + newAttr = new LongAttributeImpl(value.getLongValue()); + break; + } + case FLOAT : + { + newAttr = new FloatAttributeImpl(value.getFloatValue()); + break; + } + case DOUBLE : + { + newAttr = new DoubleAttributeImpl(value.getDoubleValue()); + break; + } + case STRING : + { + newAttr = new StringAttributeImpl(value.getStringValue()); + break; + } + case SERIALIZABLE : + { + newAttr = new SerializableAttributeImpl(value.getSerializableValue()); + break; + } + case MAP : + { + newAttr = new MapAttributeImpl((MapAttribute)value); + break; + } + default : + { + throw new AlfrescoRuntimeException("Unknown Attribute Type: " + value.getType()); + } + } + MapEntry mapEntry = new MapEntryImpl(this, entry.getKey(), newAttr); + AVMDAOs.Instance().fMapEntryDAO.save(mapEntry); + } + } + /* (non-Javadoc) * @see org.alfresco.repo.attributes.Attribute#getType() */ @@ -108,7 +181,15 @@ public class MapAttributeImpl extends AttributeImpl implements MapAttribute @Override public void put(String key, Attribute value) { - MapEntry entry = new MapEntryImpl(this, key, value); + MapEntry entry = AVMDAOs.Instance().fMapEntryDAO.get(this, key); + if (entry == null) + { + Attribute oldAttr = entry.getAttribute(); + entry.setAttribute(value); + AVMDAOs.Instance().fAttributeDAO.delete(oldAttr); + return; + } + entry = new MapEntryImpl(this, key, value); AVMDAOs.Instance().fMapEntryDAO.save(entry); } @@ -119,10 +200,13 @@ public class MapAttributeImpl extends AttributeImpl implements MapAttribute public void remove(String key) { MapEntry entry = AVMDAOs.Instance().fMapEntryDAO.get(this, key); - if (entry != null) + if (entry == null) { - AVMDAOs.Instance().fMapEntryDAO.delete(entry); + throw new AVMNotFoundException("Attribute Not Found: " + key); } + Attribute attr = entry.getAttribute(); + AVMDAOs.Instance().fMapEntryDAO.delete(entry); + AVMDAOs.Instance().fAttributeDAO.delete(attr); } /* (non-Javadoc) diff --git a/source/java/org/alfresco/repo/attributes/MapAttributeValue.java b/source/java/org/alfresco/repo/attributes/MapAttributeValue.java new file mode 100644 index 0000000000..19dd470c18 --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/MapAttributeValue.java @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import org.alfresco.error.AlfrescoRuntimeException; + +/** + * Value based implementation of a map attribute. + * @author britt + */ +public class MapAttributeValue extends AttributeValue implements MapAttribute +{ + private static final long serialVersionUID = -5090943744202078113L; + + private Map fData; + + public MapAttributeValue() + { + fData = new HashMap(); + } + + public MapAttributeValue(MapAttribute attr) + { + fData = new HashMap(); + for (Map.Entry entry : attr.entrySet()) + { + Attribute value = entry.getValue(); + Attribute newAttr = null; + switch (value.getType()) + { + case BOOLEAN : + { + newAttr = new BooleanAttributeValue((BooleanAttribute)value); + break; + } + case BYTE : + { + newAttr = new ByteAttributeValue((ByteAttribute)value); + break; + } + case SHORT : + { + newAttr = new ShortAttributeValue((ShortAttribute)value); + break; + } + case INT : + { + newAttr = new IntAttributeValue((IntAttribute)value); + break; + } + case LONG : + { + newAttr = new LongAttributeValue((LongAttribute)value); + break; + } + case FLOAT : + { + newAttr = new FloatAttributeValue((FloatAttribute)value); + break; + } + case DOUBLE : + { + newAttr = new DoubleAttributeValue((DoubleAttribute)value); + break; + } + case STRING : + { + newAttr = new StringAttributeValue((StringAttribute)value); + break; + } + case SERIALIZABLE : + { + newAttr = new SerializableAttributeValue((SerializableAttribute)value); + break; + } + case MAP : + { + newAttr = new MapAttributeValue((MapAttribute)value); + break; + } + default : + { + throw new AlfrescoRuntimeException("Unknown Attribute Type: " + value.getType()); + } + } + fData.put(entry.getKey(), newAttr); + } + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getType() + */ + public Type getType() + { + return Type.MAP; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#clear() + */ + @Override + public void clear() + { + fData.clear(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#entrySet() + */ + @Override + public Set> entrySet() + { + return fData.entrySet(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#get(java.lang.String) + */ + @Override + public Attribute get(String key) + { + return fData.get(key); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#keySet() + */ + @Override + public Set keySet() + { + return fData.keySet(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#put(java.lang.String, org.alfresco.repo.attributes.Attribute) + */ + @Override + public void put(String key, Attribute value) + { + fData.put(key, value); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#remove(java.lang.String) + */ + @Override + public void remove(String key) + { + fData.remove(key); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#values() + */ + @Override + public Collection values() + { + return fData.values(); + } +} diff --git a/source/java/org/alfresco/repo/attributes/MapEntry.java b/source/java/org/alfresco/repo/attributes/MapEntry.java index e9990bc29d..c6f1367b77 100644 --- a/source/java/org/alfresco/repo/attributes/MapEntry.java +++ b/source/java/org/alfresco/repo/attributes/MapEntry.java @@ -54,4 +54,10 @@ public interface MapEntry * @return The value attribute. */ public Attribute getAttribute(); + + /** + * Set the value of this attribute. + * @param attr + */ + public void setAttribute(Attribute attr); } diff --git a/source/java/org/alfresco/repo/attributes/MapEntryImpl.java b/source/java/org/alfresco/repo/attributes/MapEntryImpl.java index d81a8baa04..c56357ec79 100644 --- a/source/java/org/alfresco/repo/attributes/MapEntryImpl.java +++ b/source/java/org/alfresco/repo/attributes/MapEntryImpl.java @@ -39,6 +39,10 @@ public class MapEntryImpl implements MapEntry private Attribute fAttribute; + public MapEntryImpl() + { + } + public MapEntryImpl(MapAttribute map, String key, Attribute attribute) diff --git a/source/java/org/alfresco/repo/attributes/SerializableAttributeImpl.java b/source/java/org/alfresco/repo/attributes/SerializableAttributeImpl.java index 5b0b912d38..10cb091dc8 100644 --- a/source/java/org/alfresco/repo/attributes/SerializableAttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/SerializableAttributeImpl.java @@ -27,6 +27,8 @@ package org.alfresco.repo.attributes; import java.io.Serializable; +import org.alfresco.repo.avm.AVMDAOs; + /** * Persistent implemantation of a Serializable attribute. * @author britt @@ -38,9 +40,20 @@ public class SerializableAttributeImpl extends AttributeImpl implements private Serializable fValue; + public SerializableAttributeImpl() + { + } + public SerializableAttributeImpl(Serializable value) { fValue = value; + AVMDAOs.Instance().fAttributeDAO.save(this); + } + + public SerializableAttributeImpl(SerializableAttribute attr) + { + fValue = attr.getSerializableValue(); + AVMDAOs.Instance().fAttributeDAO.save(this); } /* (non-Javadoc) diff --git a/source/java/org/alfresco/repo/attributes/SerializableAttributeValue.java b/source/java/org/alfresco/repo/attributes/SerializableAttributeValue.java new file mode 100644 index 0000000000..16d25e0a96 --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/SerializableAttributeValue.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +import java.io.Serializable; + +/** + * Value based implemenation of a Serializable attribute. + * @author britt + */ +public class SerializableAttributeValue extends AttributeValue implements + SerializableAttribute +{ + private static final long serialVersionUID = 7899458940760116171L; + + private Serializable fData; + + public SerializableAttributeValue(Serializable value) + { + fData = value; + } + + public SerializableAttributeValue(SerializableAttribute attr) + { + fData = attr.getSerializableValue(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getType() + */ + public Type getType() + { + return Type.SERIALIZABLE; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#getSerializableValue() + */ + @Override + public Serializable getSerializableValue() + { + return fData; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#setSerializableValue(java.io.Serializable) + */ + @Override + public void setSerializableValue(Serializable value) + { + fData = value; + } +} diff --git a/source/java/org/alfresco/repo/attributes/ShortAttributeImpl.java b/source/java/org/alfresco/repo/attributes/ShortAttributeImpl.java index d3e57537fd..72b74bb920 100644 --- a/source/java/org/alfresco/repo/attributes/ShortAttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/ShortAttributeImpl.java @@ -25,6 +25,8 @@ package org.alfresco.repo.attributes; +import org.alfresco.repo.avm.AVMDAOs; + /** * A short attribute. * @author britt @@ -35,9 +37,20 @@ public class ShortAttributeImpl extends AttributeImpl implements ShortAttribute private short fValue; + public ShortAttributeImpl() + { + } + public ShortAttributeImpl(short value) { fValue = value; + AVMDAOs.Instance().fAttributeDAO.save(this); + } + + public ShortAttributeImpl(ShortAttribute attr) + { + fValue = attr.getShortValue(); + AVMDAOs.Instance().fAttributeDAO.save(this); } /* (non-Javadoc) diff --git a/source/java/org/alfresco/repo/attributes/ShortAttributeValue.java b/source/java/org/alfresco/repo/attributes/ShortAttributeValue.java new file mode 100644 index 0000000000..ac0ca127cf --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/ShortAttributeValue.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +/** + * Value based implementation of a short attribute. + * @author britt + */ +public class ShortAttributeValue extends AttributeValue implements + ShortAttribute +{ + private static final long serialVersionUID = -2224950695651369979L; + + private short fData; + + public ShortAttributeValue(short value) + { + fData = value; + } + + public ShortAttributeValue(ShortAttribute attr) + { + fData = attr.getShortValue(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getType() + */ + public Type getType() + { + return Type.SHORT; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#getShortValue() + */ + @Override + public short getShortValue() + { + return fData; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#setShortValue(short) + */ + @Override + public void setShortValue(short value) + { + fData = value; + } +} diff --git a/source/java/org/alfresco/repo/attributes/StringAttributeImpl.java b/source/java/org/alfresco/repo/attributes/StringAttributeImpl.java index aaa112c6f6..0c7cca30c4 100644 --- a/source/java/org/alfresco/repo/attributes/StringAttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/StringAttributeImpl.java @@ -25,6 +25,8 @@ package org.alfresco.repo.attributes; +import org.alfresco.repo.avm.AVMDAOs; + /** * Persistent implementation of String valued attribute. * @author britt @@ -36,9 +38,20 @@ public class StringAttributeImpl extends AttributeImpl implements private String fValue; + public StringAttributeImpl() + { + } + public StringAttributeImpl(String value) { fValue = value; + AVMDAOs.Instance().fAttributeDAO.save(this); + } + + public StringAttributeImpl(StringAttribute attr) + { + fValue = attr.getStringValue(); + AVMDAOs.Instance().fAttributeDAO.save(this); } /* (non-Javadoc) diff --git a/source/java/org/alfresco/repo/attributes/StringAttributeValue.java b/source/java/org/alfresco/repo/attributes/StringAttributeValue.java new file mode 100644 index 0000000000..cc6d63abf7 --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/StringAttributeValue.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +/** + * Value based implementation of a String attribute. + * @author britt + */ +public class StringAttributeValue extends AttributeValue implements + StringAttribute +{ + private static final long serialVersionUID = -5702787670770131672L; + + private String fData; + + public StringAttributeValue(String value) + { + fData = value; + } + + public StringAttributeValue(StringAttribute attr) + { + fData = attr.getStringValue(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getType() + */ + public Type getType() + { + return Type.STRING; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#getStringValue() + */ + @Override + public String getStringValue() + { + return fData; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#setStringValue(java.lang.String) + */ + @Override + public void setStringValue(String value) + { + fData = value; + } +} diff --git a/source/java/org/alfresco/repo/attributes/Value.java b/source/java/org/alfresco/repo/attributes/Value.java deleted file mode 100644 index 495205c561..0000000000 --- a/source/java/org/alfresco/repo/attributes/Value.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ - -package org.alfresco.repo.attributes; - -import java.io.Serializable; -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -/** - * Interface for polymorphic attributes. - * @author britt - */ -public interface Value extends Iterable -{ - public static enum Type implements Serializable - { - BYTE, - SHORT, - INT, - LONG, - FLOAT, - DOUBLE, - STRING, - BLOB, - SERIALIZABLE, - LIST, - MAP - }; - - /** - * Get the value type for this node. - * @return - */ - public Type getType(); - - /** - * Set a boolean value. - * @param value The value. - */ - public void setBooleanValue(boolean value); - - /** - * Get the value of a BooleanValue. - * @return The value. - */ - public boolean getBooleanValue(); - - /** - * Set a byte value. - * @param value The value to set. - */ - public void setByteValue(byte value); - - /** - * Get the value of a ByteValue. - * @return The value. - */ - public byte getByteValue(); - - /** - * Set a short value. - * @param value The value to set. - */ - public void setShortValue(short value); - - /** - * Get the value of a ShortValue. - * @return The value. - */ - public short getShortValue(); - - /** - * Set an integer value. - * @param value The value to set. - */ - public void setIntValue(int value); - - /** - * Get the integer value of an IntValue. - * @return The value. - */ - public int getIntValue(); - - /** - * Set a long value. - * @param value The value to set. - */ - public void setLongValue(long value); - - /** - * Get the long value of a LongValue. - * @return The value. - */ - public long getLongValue(); - - /** - * Set a float value. - * @param value The value to set. - */ - public void setFloatValue(float value); - - /** - * Get the value of a FloatValue. - * @return The value. - */ - public float getFloatValue(); - - /** - * Set a double value. - * @param value The value to set. - */ - public void setDoubleValue(double value); - - /** - * Get a double value from a DoubleValue. - * @return The value. - */ - public double getDoubleValue(); - - /** - * Set a String value. - * @param value The value to set. - */ - public void setStringValue(String value); - - /** - * Get a String value from a StringValue. - * @return The value. - */ - public String getStringValue(); - - /** - * Set a Blob value. - * @param value The value to set. - */ - public void setBlobValue(byte[] value); - - /** - * Get a Blob value from a BlobValue - * @return The value. - */ - public byte[] getBlobValue(); - - /** - * Set a Serializable value. - * @param value - */ - public void setSerializableValue(Serializable value); - - /** - * Get a Seriailizable value from a SerializableValue - * @return The value. - */ - public Serializable getSerializableValue(); - - /** - * Add a Value to a list. - * @param value The value to add. - */ - public void add(Value value); - - /** - * Add a Value to a list at the given index. - * @param index The offset. - * @param value The value to add. - */ - public void add(int index, Value value); - - /** - * Get the value at the given index of a list. - * @param index The offset. - * @return The value. - */ - public Value get(int index); - - /** - * Remove the given entry from a list. - * @param index The offset to remove. - */ - public void remove(int index); - - /** - * Clear a list or a map. - */ - public void clear(); - - /** - * Add an entry to a map. - * @param key The key to the entry. - * @param value The Value of the entry. - */ - public void put(String key, Value value); - - /** - * Get the Value for a key in a map. - * @param key The key. - * @return The value. - */ - public Value get(String key); - - /** - * Remove an entry by key from a map. - * @param key The key of the entry to remove. - */ - public void remove(String key); - - /** - * Get the entry set for a map. - * @return The entry set. - */ - public Set> entrySet(); - - /** - * Get the key set for a map. - * @return The key set. - */ - public Set keySet(); - - /** - * Get the collection of values of a map. - * @return The values. - */ - public Collection values(); - - /** - * Get (possibly recursively) the Value as an Object. The returned - * value is a copy of the Value using standard java Integers, Longs, Doubles, Strings, - * byte[]s, Maps, and Lists. - * @return The Object value. - */ - public Object getAsObject(); -} diff --git a/source/java/org/alfresco/repo/attributes/ValueImpl.java b/source/java/org/alfresco/repo/attributes/ValueImpl.java deleted file mode 100644 index 28d32e62a6..0000000000 --- a/source/java/org/alfresco/repo/attributes/ValueImpl.java +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ - -package org.alfresco.repo.attributes; - -import java.io.Serializable; -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; -import java.util.Map.Entry; - -/** - * The base class of the implementation of Values. - * @author britt - */ -public abstract class ValueImpl implements Value -{ - /** - * The primary key. - */ - private long fID; - - /** - * Base constructor. - */ - protected ValueImpl() - { - } - - public void setId(long id) - { - fID = id; - } - - public long getId() - { - return fID; - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#add(org.alfresco.repo.attributes.Value) - */ - public void add(Value value) - { - throw new ValueMethodNotImplementedException("Not ListValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#add(int, org.alfresco.repo.attributes.Value) - */ - public void add(int index, Value value) - { - throw new ValueMethodNotImplementedException("Not ListValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#clear() - */ - public void clear() - { - throw new ValueMethodNotImplementedException("Not ListValue or MapValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#entrySet() - */ - public Set> entrySet() - { - throw new ValueMethodNotImplementedException("Not MapValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#get(int) - */ - public Value get(int index) - { - throw new ValueMethodNotImplementedException("Not ListValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#get(java.lang.String) - */ - public Value get(String key) - { - throw new ValueMethodNotImplementedException("Not MapValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#getAsObject() - */ - public Object getAsObject() - { - throw new ValueMethodNotImplementedException("Not implemented in base class"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#getBlobValue() - */ - public byte[] getBlobValue() - { - throw new ValueMethodNotImplementedException("Not BlobValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#getDoubleValue() - */ - public double getDoubleValue() - { - throw new ValueMethodNotImplementedException("Not DoubleValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#getIntValue() - */ - public int getIntValue() - { - throw new ValueMethodNotImplementedException("Not IntValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#getLongValue() - */ - public long getLongValue() - { - throw new ValueMethodNotImplementedException("Not LongValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#getSerializableValue() - */ - public Serializable getSerializableValue() - { - throw new ValueMethodNotImplementedException("Not SerializableValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#getStringValue() - */ - public String getStringValue() - { - throw new ValueMethodNotImplementedException("Not StringValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#keySet() - */ - public Set keySet() - { - throw new ValueMethodNotImplementedException("Not MapValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#put(java.lang.String, org.alfresco.repo.attributes.Value) - */ - public void put(String key, Value value) - { - throw new ValueMethodNotImplementedException("Not MapValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#remove(int) - */ - public void remove(int index) - { - throw new ValueMethodNotImplementedException("Not ListValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#remove(java.lang.String) - */ - public void remove(String key) - { - throw new ValueMethodNotImplementedException("Not MapValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#setBlobValue(byte[]) - */ - public void setBlobValue(byte[] value) - { - throw new ValueMethodNotImplementedException("Not BlobValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#setDoubleValue(double) - */ - public void setDoubleValue(double value) - { - throw new ValueMethodNotImplementedException("Not DoubleValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#setIntValue(int) - */ - public void setIntValue(int value) - { - throw new ValueMethodNotImplementedException("Not IntValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#setLongValue(long) - */ - public void setLongValue(long value) - { - throw new ValueMethodNotImplementedException("Not LongValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#setSerializableValue(java.io.Serializable) - */ - public void setSerializableValue(Serializable value) - { - throw new ValueMethodNotImplementedException("Not SerializableValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#setStringValue(java.lang.String) - */ - public void setStringValue(String value) - { - throw new ValueMethodNotImplementedException("Not StringValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#values() - */ - public Collection values() - { - throw new ValueMethodNotImplementedException("Not MapValue"); - } - - /* (non-Javadoc) - * @see java.lang.Iterable#iterator() - */ - public Iterator iterator() - { - throw new ValueMethodNotImplementedException("Not ListValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#getBooleanValue() - */ - public boolean getBooleanValue() - { - throw new ValueMethodNotImplementedException("Not BooleanValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#getByteValue() - */ - public byte getByteValue() - { - throw new ValueMethodNotImplementedException("Not ByteValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#getFloatValue() - */ - public float getFloatValue() - { - throw new ValueMethodNotImplementedException("Not FloatValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#getShortValue() - */ - public short getShortValue() - { - throw new ValueMethodNotImplementedException("Not ShortValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#setBooleanValue(boolean) - */ - public void setBooleanValue(boolean value) - { - throw new ValueMethodNotImplementedException("Not BooleanValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#setByteValue(byte) - */ - public void setByteValue(byte value) - { - throw new ValueMethodNotImplementedException("Not ByteValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#setFloatValue(float) - */ - public void setFloatValue(float value) - { - throw new ValueMethodNotImplementedException("Not FloatValue"); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.attributes.Value#setShortValue(short) - */ - public void setShortValue(short value) - { - throw new ValueMethodNotImplementedException("Not ShortValue"); - } -} diff --git a/source/java/org/alfresco/repo/attributes/hibernate/AttributeDAOHibernate.java b/source/java/org/alfresco/repo/attributes/hibernate/AttributeDAOHibernate.java index 986d70573d..fe48e6d3b4 100644 --- a/source/java/org/alfresco/repo/attributes/hibernate/AttributeDAOHibernate.java +++ b/source/java/org/alfresco/repo/attributes/hibernate/AttributeDAOHibernate.java @@ -25,10 +25,14 @@ package org.alfresco.repo.attributes.hibernate; +import java.util.Collection; import java.util.List; import org.alfresco.repo.attributes.Attribute; import org.alfresco.repo.attributes.AttributeDAO; +import org.alfresco.repo.attributes.MapAttribute; +import org.alfresco.repo.attributes.MapEntryDAO; +import org.alfresco.repo.attributes.Attribute.Type; import org.alfresco.service.cmr.attributes.AttrQuery; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; @@ -39,11 +43,23 @@ import org.springframework.orm.hibernate3.support.HibernateDaoSupport; public class AttributeDAOHibernate extends HibernateDaoSupport implements AttributeDAO { + private MapEntryDAO fMapEntryDAO; + /* (non-Javadoc) * @see org.alfresco.repo.attributes.AttributeDAO#delete(org.alfresco.repo.attributes.Attribute) */ public void delete(Attribute attr) { + if (attr.getType() == Type.MAP) + { + MapAttribute map = (MapAttribute)attr; + Collection attrs = map.values(); + fMapEntryDAO.delete(map); + for (Attribute subAttr : attrs) + { + delete(subAttr); + } + } getSession().delete(attr); } diff --git a/source/java/org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml b/source/java/org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml index da6235ae05..8f113d3b2b 100644 --- a/source/java/org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml +++ b/source/java/org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml @@ -17,49 +17,43 @@ - + - + - + - + - + - + - + - - - - + length="512"/> - + - + - + diff --git a/source/java/org/alfresco/repo/attributes/hibernate/GlobalAttributeEntryDAOHibernate.java b/source/java/org/alfresco/repo/attributes/hibernate/GlobalAttributeEntryDAOHibernate.java index dfb29832c3..30383544e9 100644 --- a/source/java/org/alfresco/repo/attributes/hibernate/GlobalAttributeEntryDAOHibernate.java +++ b/source/java/org/alfresco/repo/attributes/hibernate/GlobalAttributeEntryDAOHibernate.java @@ -57,11 +57,9 @@ public class GlobalAttributeEntryDAOHibernate extends HibernateDaoSupport /* (non-Javadoc) * @see org.alfresco.repo.attributes.GlobalAttributeEntryDAO#get(java.lang.String) */ - public Attribute get(String name) + public GlobalAttributeEntry get(String name) { - GlobalAttributeEntry entry = - (GlobalAttributeEntry)getSession().get(GlobalAttributeEntryImpl.class, name); - return entry.getAttribute(); + return (GlobalAttributeEntry)getSession().get(GlobalAttributeEntryImpl.class, name); } /* (non-Javadoc) diff --git a/source/java/org/alfresco/service/cmr/attributes/AttributeService.java b/source/java/org/alfresco/service/cmr/attributes/AttributeService.java index 8e5ba7ce12..a1a6eef46b 100644 --- a/source/java/org/alfresco/service/cmr/attributes/AttributeService.java +++ b/source/java/org/alfresco/service/cmr/attributes/AttributeService.java @@ -47,13 +47,13 @@ public interface AttributeService * @param name The name of the Attribute. * @param value The value to set. */ - public void setAttribute(String path, Attribute value); + public void setAttribute(String path, String name, Attribute value); /** * Remove an Attribute. * @param name The name of the Attribute. */ - public void removeAttribute(String path); + public void removeAttribute(String path, String name); /** * Query for a list of attributes which are contained in the container