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 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.core.opencmis.impl.client; 020 021import java.util.Iterator; 022import java.util.List; 023 024import org.apache.chemistry.opencmis.client.api.Property; 025import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement; 026import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition; 027import org.apache.chemistry.opencmis.commons.enums.Cardinality; 028import org.apache.chemistry.opencmis.commons.enums.PropertyType; 029import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoPropertyData; 030import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoPropertyDataBase; 031 032/** 033 * Live Nuxeo document property, wrapping a {@link NuxeoPropertyData}. 034 */ 035public class NuxeoProperty<T> implements Property<T> { 036 037 private final NuxeoPropertyDataBase<T> prop; 038 039 @SuppressWarnings("unchecked") 040 public NuxeoProperty(NuxeoObject object, String id) { 041 prop = (NuxeoPropertyDataBase<T>) object.data.getProperty(id); 042 } 043 044 @Override 045 public PropertyDefinition<T> getDefinition() { 046 return prop.getPropertyDefinition(); 047 } 048 049 @Override 050 public String getDisplayName() { 051 return prop.getDisplayName(); 052 } 053 054 @Override 055 public String getId() { 056 return prop.getId(); 057 } 058 059 @Override 060 public String getLocalName() { 061 return prop.getLocalName(); 062 } 063 064 @Override 065 public String getQueryName() { 066 return prop.getQueryName(); 067 } 068 069 @Override 070 public PropertyType getType() { 071 return prop.getPropertyDefinition().getPropertyType(); 072 } 073 074 @SuppressWarnings("unchecked") 075 @Override 076 public <U> U getValue() { 077 // cast needed by Sun compiler 078 return (U) prop.getValue(); 079 } 080 081 @Override 082 public T getFirstValue() { 083 return prop.getFirstValue(); 084 } 085 086 @Override 087 public String getValueAsString() { 088 return String.valueOf(getFirstValue()); 089 } 090 091 @Override 092 public String getValuesAsString() { 093 StringBuilder buf = new StringBuilder(); 094 buf.append('['); 095 for (Iterator<T> it = getValues().iterator(); it.hasNext();) { 096 buf.append(String.valueOf(it.next())); 097 if (it.hasNext()) { 098 buf.append(", "); 099 } 100 } 101 buf.append(']'); 102 return buf.toString(); 103 } 104 105 @Override 106 public List<T> getValues() { 107 return prop.getValues(); 108 } 109 110 @Override 111 public boolean isMultiValued() { 112 return prop.getPropertyDefinition().getCardinality() == Cardinality.MULTI; 113 } 114 115 @Override 116 public List<CmisExtensionElement> getExtensions() { 117 // TODO Auto-generated method stub 118 throw new UnsupportedOperationException(); 119 } 120 121 @Override 122 public void setExtensions(List<CmisExtensionElement> extensions) { 123 // TODO Auto-generated method stub 124 throw new UnsupportedOperationException(); 125 } 126 127}