+++ /dev/null
-/*--------------------------------------------------------------------------\r
- * Copyright 2009 Taro L. Saito\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *--------------------------------------------------------------------------*/\r
-//--------------------------------------\r
-// XerialJ\r
-//\r
-// SilkClass.java\r
-// Since: Jul 3, 2009 2:41:11 PM\r
-//\r
-// $URL$\r
-// $Author$\r
-//--------------------------------------\r
-package org.xerial.silk.schema;\r
-\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-/**\r
- * Class definition\r
- * \r
- * @author leo\r
- * \r
- */\r
-public class SilkClass {\r
- public String name;\r
-\r
- public String parent = null;\r
- public String belongsTo = null;\r
-\r
- public List<String> mixin;\r
- public List<SilkAttribute> attribute = new ArrayList<SilkAttribute>();\r
-\r
- public List<SilkIndexTarget> index = new ArrayList<SilkIndexTarget>();\r
-\r
- private List<SilkAttribute> visibleAttributes = null;\r
-\r
- public SilkClass getParent(SilkSchema schema) {\r
- if (parent == null)\r
- return null;\r
-\r
- return schema.getSilkClass(parent);\r
- }\r
-\r
- /**\r
- * Returns all attributes including inherited ones.\r
- * \r
- * @param schema\r
- * @return list of visible attributes from this class definition\r
- */\r
- public List<SilkAttribute> getInheritedAttributes(SilkSchema schema) {\r
-\r
- if (visibleAttributes != null)\r
- return visibleAttributes;\r
-\r
- Map<String, SilkAttribute> table = new HashMap<String, SilkAttribute>();\r
- // from parent\r
- if (parent != null)\r
- collectInheritedAttributes(table, schema, parent);\r
-\r
- // from mixin\r
- if (mixin != null && !mixin.isEmpty()) {\r
- for (String each : mixin)\r
- collectInheritedAttributes(table, schema, each);\r
- }\r
-\r
- // from this class's own attributes\r
- for (SilkAttribute each : attribute) {\r
- table.put(each.name, each);\r
- }\r
-\r
- List<SilkAttribute> result = new ArrayList<SilkAttribute>();\r
- result.addAll(table.values());\r
- visibleAttributes = result;\r
-\r
- return visibleAttributes;\r
- }\r
-\r
- private static void collectInheritedAttributes(Map<String, SilkAttribute> result,\r
- SilkSchema schema, String className) {\r
- SilkClass c = schema.getSilkClass(className);\r
- if (c != null) {\r
- List<SilkAttribute> parentAttributes = c.getInheritedAttributes(schema);\r
- for (SilkAttribute each : parentAttributes)\r
- result.put(each.name, each);\r
- }\r
- }\r
-\r
-}\r