001/* 002 * (C) Copyright 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.apidoc.introspection; 020 021import java.util.Arrays; 022import java.util.List; 023 024import org.nuxeo.apidoc.api.BaseNuxeoArtifact; 025import org.nuxeo.apidoc.api.OperationInfo; 026import org.nuxeo.ecm.automation.OperationDocumentation; 027import org.nuxeo.ecm.automation.OperationDocumentation.Param; 028 029/** 030 * DTO for an {@link OperationInfo}, used for the runtime implementation. 031 */ 032public class OperationInfoImpl extends BaseNuxeoArtifact implements OperationInfo { 033 034 public final OperationDocumentation op; 035 036 public final String version; 037 038 protected final String operationClass; 039 040 protected final String contributingComponent; 041 042 public OperationInfoImpl(OperationDocumentation op, String version, String operationClass, 043 String contributingComponent) { 044 this.op = op; 045 this.version = version; 046 this.operationClass = operationClass; 047 if (contributingComponent == null || contributingComponent.isEmpty()) { 048 this.contributingComponent = OperationInfo.BUILT_IN; 049 } else { 050 String[] parts = contributingComponent.split(":"); 051 if (parts.length > 1) { 052 this.contributingComponent = parts[1]; 053 } else { 054 this.contributingComponent = contributingComponent; 055 } 056 } 057 } 058 059 @Override 060 public String getName() { 061 return op.getId(); 062 } 063 064 @Override 065 public String getId() { 066 return ARTIFACT_PREFIX + op.getId(); 067 } 068 069 @Override 070 public String[] getAliases() { 071 return op.getAliases(); 072 } 073 074 @Override 075 public String getDescription() { 076 return op.getDescription(); 077 } 078 079 @Override 080 public String[] getSignature() { 081 return op.getSignature(); 082 } 083 084 @Override 085 public String getCategory() { 086 return op.getCategory(); 087 } 088 089 @Override 090 public String getUrl() { 091 return op.getUrl(); 092 } 093 094 @Override 095 public String getLabel() { 096 return op.getLabel(); 097 } 098 099 @Override 100 public String getRequires() { 101 return op.getRequires(); 102 } 103 104 @Override 105 public String getSince() { 106 return op.since; 107 } 108 109 @Override 110 public List<Param> getParams() { 111 return Arrays.asList(op.getParams()); 112 } 113 114 @Override 115 public String getVersion() { 116 return version; 117 } 118 119 @Override 120 public String getArtifactType() { 121 return TYPE_NAME; 122 } 123 124 @Override 125 public String getHierarchyPath() { 126 return "/"; 127 } 128 129 @Override 130 public int compareTo(OperationInfo o) { 131 String s1 = getLabel() == null ? getId() : getLabel(); 132 String s2 = o.getLabel() == null ? o.getId() : o.getLabel(); 133 return s1.compareTo(s2); 134 } 135 136 public String getOperationClass() { 137 return operationClass; 138 } 139 140 public String getContributingComponent() { 141 return contributingComponent; 142 } 143 144}