001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * bstefanescu 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.ecm.core.api.model.impl; 016 017import java.io.Serializable; 018 019import org.nuxeo.common.utils.Path; 020import org.nuxeo.ecm.core.api.PropertyException; 021import org.nuxeo.ecm.core.api.model.DocumentPart; 022import org.nuxeo.ecm.core.api.model.Property; 023import org.nuxeo.ecm.core.api.model.PropertyDiff; 024import org.nuxeo.ecm.core.api.model.PropertyVisitor; 025import org.nuxeo.ecm.core.schema.types.Field; 026import org.nuxeo.ecm.core.schema.types.Schema; 027 028/** 029 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 030 */ 031public class DocumentPartImpl extends ComplexProperty implements DocumentPart { 032 033 private static final long serialVersionUID = 1L; 034 035 protected Schema schema; 036 037 public DocumentPartImpl(Schema schema) { 038 super(null); 039 this.schema = schema; 040 } 041 042 @Override 043 public void internalSetValue(Serializable value) throws PropertyException { 044 } 045 046 @Override 047 public boolean isContainer() { 048 return true; 049 } 050 051 @Override 052 public Schema getSchema() { 053 return schema; 054 } 055 056 @Override 057 public String getName() { 058 return schema.getName(); 059 } 060 061 @Override 062 public Schema getType() { 063 return schema; 064 } 065 066 @Override 067 public Field getField() { 068 throw new UnsupportedOperationException("Document parts are not bound to schema fields"); 069 } 070 071 @Override 072 public Path collectPath(Path path) { 073 return path; 074 } 075 076 @Override 077 public Object clone() throws CloneNotSupportedException { 078 return super.clone(); 079 } 080 081 @Override 082 public void accept(PropertyVisitor visitor, Object arg) throws PropertyException { 083 visitChildren(visitor, arg); 084 } 085 086 @Override 087 public Property createProperty(Property parent, Field field) { 088 return createProperty(parent, field, 0); 089 } 090 091 @Override 092 public Property createProperty(Property parent, Field field, int flags) { 093 return PropertyFactory.createProperty(parent, field, flags); 094 } 095 096 @Override 097 public PropertyDiff exportDiff() { 098 return null; 099 } 100 101 @Override 102 public void importDiff(PropertyDiff diff) { 103 } 104 105 public boolean isSameAs(DocumentPart dp) { 106 if (dp == null) { 107 return false; 108 } 109 if (dp instanceof ComplexProperty) { 110 return getNonPhantomChildren().equals(((ComplexProperty) dp).getNonPhantomChildren()); 111 } 112 return false; 113 } 114 115 @Override 116 public String toString() { 117 return getClass().getSimpleName() + '(' + getName() + (isDirty() ? "*" : "") + ", " + children + ')'; 118 } 119 120}