001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.core.api.model.impl; 023 024import java.io.Serializable; 025 026import org.nuxeo.common.utils.Path; 027import org.nuxeo.ecm.core.api.PropertyException; 028import org.nuxeo.ecm.core.api.model.DocumentPart; 029import org.nuxeo.ecm.core.api.model.Property; 030import org.nuxeo.ecm.core.api.model.PropertyDiff; 031import org.nuxeo.ecm.core.api.model.PropertyVisitor; 032import org.nuxeo.ecm.core.schema.types.Field; 033import org.nuxeo.ecm.core.schema.types.Schema; 034 035/** 036 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 037 */ 038public class DocumentPartImpl extends ComplexProperty implements DocumentPart { 039 040 private static final long serialVersionUID = 1L; 041 042 protected Schema schema; 043 044 public DocumentPartImpl(Schema schema) { 045 super(null); 046 this.schema = schema; 047 } 048 049 @Override 050 public void internalSetValue(Serializable value) throws PropertyException { 051 } 052 053 @Override 054 public boolean isContainer() { 055 return true; 056 } 057 058 @Override 059 public Schema getSchema() { 060 return schema; 061 } 062 063 @Override 064 public String getName() { 065 return schema.getName(); 066 } 067 068 @Override 069 public Schema getType() { 070 return schema; 071 } 072 073 @Override 074 public Field getField() { 075 throw new UnsupportedOperationException("Document parts are not bound to schema fields"); 076 } 077 078 @Override 079 public Path collectPath(Path path) { 080 return path; 081 } 082 083 @Override 084 public Object clone() throws CloneNotSupportedException { 085 return super.clone(); 086 } 087 088 @Override 089 public void accept(PropertyVisitor visitor, Object arg) throws PropertyException { 090 visitChildren(visitor, arg); 091 } 092 093 @Override 094 public Property createProperty(Property parent, Field field) { 095 return createProperty(parent, field, 0); 096 } 097 098 @Override 099 public Property createProperty(Property parent, Field field, int flags) { 100 return PropertyFactory.createProperty(parent, field, flags); 101 } 102 103 @Override 104 public PropertyDiff exportDiff() { 105 return null; 106 } 107 108 @Override 109 public void importDiff(PropertyDiff diff) { 110 } 111 112 public boolean isSameAs(DocumentPart dp) { 113 if (dp == null) { 114 return false; 115 } 116 if (dp instanceof ComplexProperty) { 117 return getNonPhantomChildren().equals(((ComplexProperty) dp).getNonPhantomChildren()); 118 } 119 return false; 120 } 121 122 @Override 123 public String toString() { 124 return getClass().getSimpleName() + '(' + getName() + (isDirty() ? "*" : "") + ", " + children + ')'; 125 } 126 127}